JMamtora JMamtora - 1 year ago 62
Python Question

Get the count of the each date entry from onr of the raw from CSV file

I am working on getting values and creating a chart from CSV file using python.
How to get the number of entry of the each date? For Example, sample Date row:

4/14/2016 11:05:15 AM
4/14/2016 09:06:15 PM
6/14/2016 11:05:15 AM

It should gives an output as

4/14/2016 entry 2 times
6/14/2016 entry 1 time

Answer Source

you can use itertools.groupby:

with open("your_file.csv") as f:
    for x,y in itertools.groupby(sorted(map(str.split,"\n"))), key = lambda x:x[0]):
        print x,len(list(y))


4/14/2016 2
6/14/2016 1