-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleanCrimeFile.py
More file actions
68 lines (45 loc) · 1.55 KB
/
Copy pathcleanCrimeFile.py
File metadata and controls
68 lines (45 loc) · 1.55 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pandas as pd
import numpy as np
import random
def cleanFile():
file = pd.read_csv('crime.csv', encoding = 'latin-1')
#print(list(file))
file = file.drop(['INCIDENT_NUMBER', "HOUR", "STREET", "Location", "OFFENSE_CODE",
"UCR_PART", "REPORTING_AREA", "DISTRICT", "OFFENSE_CODE_GROUP", "DAY_OF_WEEK",
"SHOOTING"], axis = 1)
file = file[0:2500]
return (file)
def main():
cleanedFile = cleanFile()
Israel = pd.read_csv("lat_long.csv")
Israel['Type'] = "Missle"
Islat = list(Israel['Latitude'])
Islon = list(Israel['Longitude'])
# Islat = [x for x in Islat if str(x) != 'nan' and x < 35 and x > 28]
# Islon = [x for x in Islon if str(x) != 'nan' and x > 30 and x < 50]
Bolat = cleanedFile['Lat']
Bolon = cleanedFile['Long']
Bolat = [x for x in Bolat if str(x) != 'nan']
Bolon = [x for x in Bolon if str(x) != 'nan']
BolatNew = []
BolonNew = []
minIslat = np.min(Islat)
maxIslat = np.max(Islat)
minIslon = np.min(Islon)
maxIslon = np.max(Islon)
for i in range(len(cleanedFile['Lat'])):
newLat = random.choice(Islat)
newLon = random.choice(Islon)
BolatNew.append(newLat)
BolonNew.append(newLon)
cleanedFile['Latitude'] = BolatNew
cleanedFile['Longitude'] = BolonNew
cleanedFile['Type'] = "Crime"
newDf = pd.DataFrame()
cleanedFile =cleanedFile[['Latitude', 'Longitude', 'Type']]
Israel = Israel[['Latitude', "Longitude", "Type"]]
frames = [cleanedFile, Israel]
result = pd.concat(frames)
print(result)
result.to_csv('combined_long_lat.csv')
main()