The code below counts the amounts of occurrences of individual years in a row of a CSV file.
import csv
from collections import Counter
out=open("meteors.csv", "r")
data=csv.reader(out)
data.next()
data=[row for row in data]
out.close()
year = []
for row in data:
if row[2]=='':
continue
else:
year.append(row[2])
c = Counter(year)
print c
The results come out like this:
Counter ({'2012':15, '2004':10, '2008':4})
Can anyone give me a piece of code I can add in order to sort the results by year?