ECSP




Pay Notebook Creator: Haige Cui0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0
In [1]:
# CrossCompute
input_table_path = 'address.csv'
target_folder = '/tmp'
import pandas as pd
In [2]:
result_table = pd.read_csv('result-table.csv')
In [3]:
result_table
Out[3]:
<style scoped> .dataframe tbody tr th:only-of-type { vertical-align: middle; } .dataframe tbody tr th { vertical-align: top; } .dataframe thead th { text-align: right; } </style>
Business Address Building Identification Number Tree Count Within X Miles Minimum Estimated Savings Maximum Estimated Savings Savings Over Investment Ratio Recommendation
0 128-12 18th Ave., Queens, NY 4098985 23 4000 6000 0.5 NO
1 1109 Metropolitan Avenue, Brooklyn, NY 3070491 1 1200 1300 1.5 YES
2 409-423 Willoughby Avenue, Brooklyn, NY 3048569 5 1400 1500 1.1 YES
In [4]:
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
result_table_path = /tmp/result-table.csv
result_geotable_path = /tmp/result-map.csv
In [5]:
from geopy import GoogleV3
geocode = GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode 
In [6]:
def get_location(row):
    location = geocode(row['Business Address'])
    row['Longitude'] = location.longitude
    row['Latitude'] = location.latitude
    return row
In [ ]:
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)
In [ ]: