-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgeocodeNPI.py
28 lines (20 loc) · 934 Bytes
/
geocodeNPI.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
# geocodes addresses in a given .csv (the mailing and practice location addresses of an excerpt from the NPI file)
import geocoder
i = open("HI4.csv", "r", encoding="utf8")
o = open("HI4g.csv", "w")
k = "<put your mapquest api key in here - 5,000 geocode request limit - per day>"
for row in i:
fields = row.split(",")
# MAILING ADDRESS
adrM = fields[20].replace("\"","") + "," + fields[22].replace("\"","") + "," + fields[23].replace("\"","") + "," + fields[24].replace("\"","")
g = geocoder.mapquest(adrM, key=k)
oRec = fields[0] + "," + str(g.lat) + "," + str(g.lng)
# PRACTICE LOCATION ADDRESS
adrB = fields[28].replace("\"","") + "," + fields[30].replace("\"","") + "," + fields[31].replace("\"","") + "," + fields[32].replace("\"","")
if adrM != adrB:
g = geocoder.mapquest(adrB, key=k)
oRec = oRec + "," + str(g.lat) + "," + str(g.lng) + "~"
print (oRec)
o.write(oRec)
i.close()
o.close()