So i have this csv file and one collumn looks like this:
1022
1040
1042
1035
11728
1036
1022
1040
1042
1035
11728
1036
1022
1040
1042
1035
11728
Now i need to count how oftend a number occurs. I need this to make a graphic picture with matplotlib. So the graphic will show how much a number occurs (in this situation it’s a event id)
so far i only have the code to print that row…
my_reader = csv.reader(open(csvpath))
for col in my_reader:
print col[3]
how do i count how often a number in that specific collumn occurs?
Just create a mapping from number to count. The
collections.Counter()class makes that easiest:Using a
collections.defaultdictis also an option:or you can use a normal
dict: