-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConvertLocation.py
54 lines (39 loc) · 1.27 KB
/
ConvertLocation.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 requests
import json
import pandas as pd
from arcgis.gis import GIS
from arcgis.geocoding import reverse_geocode
from arcgis.geometry import Geometry
import math
def FindAdress(row):
if (math.isnan(row['X Coordinate'])) or (math.isnan(row['Y Coordinate'])):
return None,None,None
else:
pt = Geometry({
"x": row['X Coordinate'],
"y": row['Y Coordinate'],
"spatialReference": {
"wkid": 3435
}
})
try:
result = reverse_geocode(pt)
return pd.Series({
'Neighborhood': result['address']['Neighborhood'],
'Zipcode': result['address']['Postal'],
'Address': result})
except:
return pd.Series({
'Neighborhood': None,
'Zipcode': None,
'Address': None})
file = 'Crimes.csv'
data = pd.read_csv(file)
testData = data[1300001:1350001]#lower and upper bound of rows your are converting
gis = GIS("https://univofillinois.maps.arcgis.com/home/index.html", "username", "password")
newcolumns = testData.apply(FindAdress,axis=1)
testData['Neighborhood'] = newcolumns['Neighborhood']
testData['Zipcode'] = newcolumns['Zipcode']
testData['Address'] = newcolumns['Address']
print(testData.shape)
testData.to_csv('1300001To1350000.csv')#add name of outputfile. Nameformat: LowerBoundToUpperbound.csv. For example: 0To99.csv