-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcleandataall_delete_empty_comm_and_separate_time_attrib.py
44 lines (40 loc) · 16.9 KB
/
cleandataall_delete_empty_comm_and_separate_time_attrib.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
import csv
import time
import datetime
# 0 ID,1 Date,2 Primary Type,3 Description
# 4 Community Area,5 Year,6 Latitude,7 Longitude
f = open('CrimesAll_final.csv', 'rb')
res = open('CrimesAll_final11.csv', 'wb')
csvread = csv.reader(f)
csvwrite = csv.writer(res)
count = 0
for line in csvread:
if (cmp(line[4],'')==0):
continue
#print line[1]
month = int(line[1][0])*10+int(line[1][1])
#print month
day = int(line[1][3])*10+int(line[1][4])
#print day
week = datetime.datetime(int(line[5]),month,day).strftime("%w")
#print week
hour = int(line[1][11])*10+int(line[1][12])
if (cmp(line[1][20],'P')==0):
hour+=12
if (hour==12) or (hour==24):
hour-=12
#print hour
csvwrite.writerow((line[0],week,line[2],line[3],line[4],line[5],line[6],line[7],month,day,hour))
# 0 ID
# 1 day of week
# 2 type
# 3 description
# 4 comm
# 5 year
# 6 lat
# 7 lon
# 8 month
# 9 date
# 10 hour
f.close()
res.close()