cours-snt/donnees_structurees/tp_decouverte_csv/programme.py

28 lines
920 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import csv
def afficher_descripteurs ():
""" Cette fonction affiche la première ligne du fichier csv """
with open('centres-vaccination.csv', 'r', encoding='utf8') as f:
print(f.readline())
def compter_les_colonnes ():
""" Cette fonction compte le nombre dentrées renseignées pour chaque colonne """
compte = {}
with open('centres-vaccination.csv', 'r', encoding='utf8') as f:
title = f.readline().strip().split(';')
for ligne in f.readlines():
for (index, element) in zip(title,ligne.strip().split(';')):
if index not in compte:
compte[index] = 0
if element.strip() != '':
compte[index] += 1
return compte
def afficher_compte_colonnes ():
colonnes = compter_les_colonnes()
for index in colonnes:
print(index, ' : ', colonnes[index])
afficher_compte_colonnes()