# CrossCompute
input_table_path = 'address.csv'
target_folder = '/tmp'
import pandas as pd
result_table = pd.read_csv('result-table.csv')
result_table
from os.path import join
target_path = join(target_folder, 'result-table.csv')
result_table.to_csv(target_path, index=False)
print('result_table_path = %s' % target_path) # Show table
target_path = join(target_folder, 'result-map.csv')
result_geotable = result_table.copy()
result_geotable['FillReds'] = result_geotable['Savings Over Investment Ratio']
result_geotable.to_csv(target_path, index=False)
print('result_geotable_path = %s' % target_path) # Show map
from geopy import GoogleV3
geocode = GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
def get_location(row):
location = geocode(row['Business Address'])
row['Longitude'] = location.longitude
row['Latitude'] = location.latitude
return row
from geopy.geocoders import GoogleV3
googleGeo = GoogleV3('googleKey')
# create a geocoded list containing geocode objects
geocoded = []
for address in mydata['location']: # assumes mydata is a pandas df
geocoded.append(googleGeo.geocode(address)) # geocode function returns a geocoded object
# append geocoded list to mydata
mydata['geocoded'] = geocoded
# create coordinates column
mydata['coords'] = mydata['geocoded'].apply(lambda x: (x.latitude, x.longitude))
# if you want to split our your lat and long then do
# mydata['lat'] = mydata['geocoded'].apply(lambda x: x.latitude)
# mydata['long'] = mydata['geocoded'].apply(lambda x: x.longitude)