Skip to content

Instantly share code, notes, and snippets.

@outout14
Created February 9, 2023 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save outout14/db11c46e72756e5210c3ac3ec8a493ea to your computer and use it in GitHub Desktop.
Save outout14/db11c46e72756e5210c3ac3ec8a493ea to your computer and use it in GitHub Desktop.
import csv
with open('liste01.csv', 'r', encoding="latin-1") as f:
lecture = csv.reader(f, delimiter=";")
data = list(lecture)
data = data[1:5]
compteur = {}
for ligne in data:
print(f"ligne : {ligne}")
print(f"colonne 3 : {ligne[2]}")
# Compter :
try: # Essayer si l'index correspondant à la valeur de la troisieme colonne existe dans le compteur, on l'incrémente de 1
compteur[ligne[2]] += 1
except: # Si il existe pas on créait l'index et on l'initialise a 1
compteur[ligne[2]] = 1
# En gros le compteur est un tableau qui contient un compteur par valeur.
# Si on a 3 valeurs de "TS40", compteur["TS40"] sera égal à 3.
print(compteur)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment