Skip to content

Instantly share code, notes, and snippets.

@coleGillespie coleGillespie/
Last active Aug 29, 2015

What would you like to do?
analyze a csv of local violations
import csv
import operator
count = 1
previousCategory = None
previousDate = None
previousCount = 1
with open('Violations-2012.csv', 'rb') as csvfile:
spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
sortedlist = sorted(spamreader, key=operator.itemgetter(2, 3), reverse=False)
for i, row in enumerate(sortedlist):
if previousCategory != row[2]:
if previousCategory != None:
print "Latest Entry in", previousCategory, "happend on", previousDate
print previousCategory, "has", count, "total entries"
print ""
if i +1 != len(sortedlist):
print "Earliest Entry in", row[2], "happend on", row[3]
count = 1
count = count + 1
previousCategory = row[2]
previousDate = row[3]
previousCount = count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.