-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleandataall.py
52 lines (50 loc) · 18 KB
/
cleandataall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import csv
# 0 ID,1 Case Number,2 Date,3 Block,4 IUCR,5 Primary Type,6 Description
# 7 Location Description,8 Arrest,9 Domestic,10 Beat,11 District,12 Ward,
# 13 Community Area,14 FBI Code,15 X Coordinate,16 Y Coordinate,17 Year,
# 18 Updated On,19 Latitude,20 Longitude,21 Location
f = open('CrimesAll.csv', 'rb')
res = open('CrimesAll_final.csv', 'wb')
csvread = csv.reader(f)
csvwrite = csv.writer(res)
count = 0
atLine = 0
for line in csvread:
if atLine == 0:
csvwrite.writerow((line[0],line[2],line[5],line[6],line[13],line[17],line[19],line[20]))
atLine = 1
continue
if (cmp(line[15],'')==0):
continue
# ROBBERY & HOMICIDE & MOTOR VEHICLE THEFT
if (cmp(line[5],'ROBBERY') == 0) or (cmp(line[5], 'HOMICIDE') == 0) or (cmp(line[5], 'MOTOR VEHICLE THEFT') == 0):
csvwrite.writerow((line[0],line[2],line[5],line[6],line[13],line[17],line[19],line[20]))
count+=1
print count
else:
# CRIMINAL DAMAGE that TO CITY OF CHICAGO PROPERTY or end with VANDALISM
if (cmp(line[5], 'CRIMINAL DAMAGE') == 0) and (cmp(line[6], 'TO CITY OF CHICAGO PROPERTY')==0 or line[6].endswith('VANDALISM')):
csvwrite.writerow((line[0],line[2],line[5],line[6],line[13],line[17],line[19],line[20]))
count+=1
print count
else:
# THEFT that is OVER $500
if (cmp(line[5], 'THEFT')==0) and (cmp(line[6], 'OVER $500')==0):
csvwrite.writerow((line[0],line[2],line[5],line[6],line[13],line[17],line[19],line[20]))
count+=1
print count
else:
# ASSULT & CRIM SEXUAL ASSAULT that start with AGGRAVATED
if (cmp(line[5], 'ASSAULT')==0) or (cmp(line[5], 'CRIM SEXUAL ASSAULT')==0):
if (line[6].find('AGGRAVATED') == 0): # start
csvwrite.writerow((line[0],line[2],line[5],line[6],line[13],line[17],line[19],line[20]))
count+=1
print count
else:
# BURGLARY that is FORCIBEL ENTRY
if (cmp(line[5], 'BURGLARY') == 0) and (cmp(line[6], 'FORCIBLE ENTRY')==0):
csvwrite.writerow((line[0],line[2],line[5],line[6],line[13],line[17],line[19],line[20]))
count+=1
print count
f.close()
res.close()