Last active
August 29, 2015 14:04
-
-
Save cole-gillespie/3e326b4433d2d0b9feeb to your computer and use it in GitHub Desktop.
analyze a csv of local violations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| else: | |
| 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