Created
May 6, 2016 13:44
-
-
Save Abdujabbar/c32b3b01f8610be28f62b1e741f97ef2 to your computer and use it in GitHub Desktop.
stepic python
This file contains 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 | |
from datetime import datetime | |
def validate_date(d): | |
try: | |
datetime.strptime(d, r'%m/%d/%Y %H:%M:%S %p') | |
return True | |
except ValueError: | |
return False | |
with open("Crimes.csv") as f: | |
reader = csv.reader(f) | |
c = 0 | |
_dict = dict() | |
for line in reader: | |
if c == 0: | |
c += 1 | |
continue | |
if validate_date(line[2]) and '2015' in line[2]: | |
if line[6] not in _dict.keys(): | |
_dict[line[6]] = 1 | |
else: | |
_dict[line[6]] += 1 | |
__dict = sorted(_dict.items(), key=operator.itemgetter(1), reverse=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment