# CrossCompute
address_table_path = 'address.csv'
search_radius_in_miles = 0.5
industry_select = """
Manufacturing
Manufacturing
Wholesale/Warehouse/Distribution
Commercial
Landlord
Public Benefit Corp
Other
"""
program_select = """
ICIP
City/State
ICAP
ICIP
IDA
Relocator
Tenant
"""
target_folder = '/tmp'
# Load inputs
import pandas as pd
address_table = pd.read_csv(address_table_path)
industry = industry_select.strip().splitlines()[0]
program = program_select.strip().splitlines()[0]
# Get longitude and latitude for each address
from geopy import GoogleV3
geocode = GoogleV3('AIzaSyDNqc0tWzXHx_wIp1w75-XTcCk4BSphB5w').geocode
def get_longitude_latitude(row):
location = geocode(row['Address'])
row['Longitude'] = location.longitude
row['Latitude'] = location.latitude
return row
address_table = address_table.apply(get_longitude_latitude, axis=1)
address_table[:3]
# Prepare prediction dataset
prediction_table = address_table.copy()
# Prepare prediction dataset
prediction_table = address_table.copy()
# Add "Average Monthly Savings of Buildings Within 0.5 Mile Radius" column
prediction_table['Average Monthly Savings of Buildings Within 0.5 Mile Radius'] = [100, 200, 300]
# Add "Tree Count Within 0.5 Mile Radius"
prediction_table['Tree Count Within 0.5 Mile Radius'] = [10, 20, 30]
# # Load your model
# from pickle import load
# model = load(open('dummy-model.pkl', 'rb'))
# model
# # Run your model to add column "Monthly Savings"
prediction_table['Monthly Savings'] = [1, 2, 3]
X = prediction_table[['Average Monthly Savings of Buildings Within 0.5 Mile Radius', 'Tree Count Within 0.5 Mile Radius']].values
## prediction_table['Monthly Savings'] = model.predict(X)
target_path = target_folder + '/savings.csv'
prediction_table.to_csv(target_path, index=False)
print(f'prediction_table_path = {target_path}')
target_path = target_folder + '/savings-map.csv'
map_table = prediction_table.copy()
map_table['RadiusInPixelsRange3-30'] = map_table['Monthly Savings']
map_table['FillColor'] = ['y' if index in address_table else 'b' for index in map_table.index]
map_table.to_csv(target_path, index=False)
print(f'prediction_geotable_path = {target_path}')
%matplotlib inline
axes = prediction_table[[
'Monthly Savings',
]].plot(kind='bar')
# Save file to target folder to include it in the result download
target_path = target_folder + '/c.png'
figure = axes.get_figure()
figure.savefig(target_path)
print(f'c_image_path = {target_path}')