-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaccessingCSVLatLong.py
More file actions
33 lines (28 loc) · 1.03 KB
/
Copy pathaccessingCSVLatLong.py
File metadata and controls
33 lines (28 loc) · 1.03 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
import pandas as pd
import csv
import math
from convertLatLong import findLatLong
datafile = pd.read_csv("limited_inputs.csv", usecols=['to_address1', 'to_address2'])
# for testing, will only use 3 random values in the list to run the google api to avoid
# exceeding limit
# limited_dataset = pd.read_csv("customer_addresses_id.csv", usecols=['to_address1','to_address2'], nrows=3)
#print (limited_dataset)
merged_addresses = []
for index, row in datafile.iterrows():
#print(row['to_address2'])
if (str(row['to_address2']) != "nan"):
merged_addresses.append(row['to_address1'] + row['to_address2'])
else:
merged_addresses.append(row['to_address1'])
list_of_lat_long = []
for address in merged_addresses:
latLong = findLatLong(address)
#print (latLong)
list_of_lat_long.append(latLong)
with open('latlong.csv', 'w', newline='') as file:
writer = csv.writer(file)
for item in list_of_lat_long:
if (item == None):
writer.writerow([item])
else:
writer.writerow(item)