ECSP




Pay Notebook Creator: Haige Cui0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0
In [5]:
# CrossCompute
ready_table_path = 'Table with average monthly savings(within 0.5 Mile) and tree count(within 0.5 Mile).csv'
target_folder = '/tmp'

Load Arguments

In [6]:
import pandas as pd
# import libraries
import subprocess
subprocess.call('pip install folium'.split())
import folium
ready_table = pd.read_csv(ready_table_path)
In [7]:
ready_table.head()
Out[7]:
<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>
Unnamed: 0 Unnamed: 0.1 Company Name BIN Industry Business Program Effective Date Address Postcode Borough Latitude Longitude Month Count Periodic Savings Total Tree Count within 0.5 Mile Periodic Savings within 0.5 Mile
0 0 0 139 ACA Realty, Inc. 4003160 Commercial Limousine Service ICIP 2008-04-07 43-23 35th Street 11101 QUEENS 40.745706 -73.929565 116 1068.75 683 1423.931818
1 1 1 141 Lake Avenue Realty c/o JR Produce, Inc. 5146740 Wholesale/Warehouse/Distribution Dist. of prepacked salads ICIP 2009-12-08 141 Lake Avenue 10303 STATEN IS 40.633153 -74.150999 96 494.93 21 336.525000
2 2 2 14-10 123rd Street LLC 4098344 Commercial Electrical Parts Mfg. ICIP 2011-03-04 14-10 123rd Street 11356 QUEENS 40.785144 -73.844833 81 263.25 447 1079.380000
3 3 3 183 Lorriane Street LLC 3336622 Wholesale/Warehouse/Distribution Commercial Storage facility ICIP 2015-11-06 183 Lorraine Street 11231 BROOKLYN 40.673106 -74.002300 25 4200.66 224 2846.165714
4 4 4 21st Century Optics, Inc. 4003447 Manufacturing Eye glasses Tenant 2009-01-07 47-00 33rd Street 11101 QUEENS 40.742386 -73.932148 107 2016.42 658 1524.019111
In [8]:
len(ready_table)
Out[8]:
502
In [9]:
ready_table.drop(ready_table.columns[[0,1]], axis=1, inplace=True)
ready_table.head()
Out[9]:
<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>
Company Name BIN Industry Business Program Effective Date Address Postcode Borough Latitude Longitude Month Count Periodic Savings Total Tree Count within 0.5 Mile Periodic Savings within 0.5 Mile
0 139 ACA Realty, Inc. 4003160 Commercial Limousine Service ICIP 2008-04-07 43-23 35th Street 11101 QUEENS 40.745706 -73.929565 116 1068.75 683 1423.931818
1 141 Lake Avenue Realty c/o JR Produce, Inc. 5146740 Wholesale/Warehouse/Distribution Dist. of prepacked salads ICIP 2009-12-08 141 Lake Avenue 10303 STATEN IS 40.633153 -74.150999 96 494.93 21 336.525000
2 14-10 123rd Street LLC 4098344 Commercial Electrical Parts Mfg. ICIP 2011-03-04 14-10 123rd Street 11356 QUEENS 40.785144 -73.844833 81 263.25 447 1079.380000
3 183 Lorriane Street LLC 3336622 Wholesale/Warehouse/Distribution Commercial Storage facility ICIP 2015-11-06 183 Lorraine Street 11231 BROOKLYN 40.673106 -74.002300 25 4200.66 224 2846.165714
4 21st Century Optics, Inc. 4003447 Manufacturing Eye glasses Tenant 2009-01-07 47-00 33rd Street 11101 QUEENS 40.742386 -73.932148 107 2016.42 658 1524.019111
In [10]:
#ready_table = ready_table[['Longitude','Latitude','Total Tree Count within 0.5 Mile','Periodic Savings within 0.5 Mile']]
#ready_table=ready_table
len(ready_table)
Out[10]:
502
In [11]:
len(ready_table)
Out[11]:
502
In [12]:
# Make a data frame with dots to show on the map
# data = pd.DataFrame({
# 'lat':[-58, 2, 145, 30.32, -4.03, -73.57, 36.82, -38.5],
# 'lon':[-34, 49, -38, 59.93, 5.33, 45.52, -1.29, -12.97],
# 'name':['Buenos Aires', 'Paris', 'melbourne', 'St Petersbourg', 'Abidjan', 'Montreal', 'Nairobi', 'Salvador']
# })
# data
In [16]:
 # Make an empty map
m = folium.Map(location=[20, 0], tiles="Mapbox Bright", zoom_start=2)
 
# I can add marker one by one on the map
for i in range(0,len(ready_table)):
    folium.Marker([ready_table.iloc[i]['Longitude'], ready_table.iloc[i]['Latitude']], popup=ready_table.iloc[i]['Total Tree Count within 0.5 Mile']).add_to(m)
m.save('312_markers_on_folium_map1.html')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-16-1f63ba64e252> in <module>
      4 # I can add marker one by one on the map
      5 for i in range(0,len(ready_table)):
----> 6    folium.Marker([ready_table.iloc[i]['Longitude'], ready_table.iloc[i]['Latitude']], popup=ready_table.iloc[i]['Total Tree Count within 0.5 Mile']).add_to(m)
      7 m.save('312_markers_on_folium_map1.html')

~/.virtualenvs/crosscompute/lib/python3.6/site-packages/folium/map.py in __init__(self, location, popup, tooltip, icon)
    256             self.add_child(Popup(popup))
    257         elif popup is not None:
--> 258             self.add_child(popup)
    259         if isinstance(tooltip, Tooltip):
    260             self.add_child(tooltip)

~/.virtualenvs/crosscompute/lib/python3.6/site-packages/branca/element.py in add_child(self, child, name, index)
    106         """Add a child."""
    107         if name is None:
--> 108             name = child.get_name()
    109         if index is None:
    110             self._children[name] = child

AttributeError: 'numpy.int64' object has no attribute 'get_name'

Render Map

In [ ]:
ready_geotable = ready_table.copy()  # Prevent SettingwithCopyWarning
In [ ]:
# Set radius for each point
# The bigger the circle, the more the company saved
ready_geotable['RadiusInPixelsRange5-50'] = ready_geotable['Periodic Savings']
In [ ]:
# Set color for each point using a gradient
# The darker the color, the more trees the company is surrounded by
ready_geotable['FillRedsFromMean'] = ready_geotable['Total Tree Count within 0.5 Mile']

Hypothesis:<br>

  • Bigger circle tend to be darker<br>
  • Also, companies who saved the more money tend to be surrounded by more trees.<br> Discovery:
  • Biggest circles are found in Bronx and STATEN IS<br>
  • Bigger circles in Bronx are indeed surrounded by more trees<br> (ex.Albert Einstein College of Medicine of Yeshiva Uni, saved 102919.54, 419 trees<br> Montefiore Medical Center, saved 11400.63 in ICAP and 69506.82 in ICIP, 303 trees) <br>
  • While the biggest circle of all is found in Stanley IS but the color is near transparent(means very few trees around) (ex.VISY PAPER RECYCLING saved 274038.51, 41 trees)
In [ ]:
 
In [ ]:
# See what we did
ready_geotable[:3]
In [ ]:
# Save file to target folder to include it in the result download
target_path = target_folder + '/b.csv'
ready_geotable.to_csv(target_path, index=False)
print(f'b_geotable_path = {target_path}')  # Print geotable_path to render map

Render Plot

In [ ]:
# %matplotlib inline
# axes = address_table[[
#     'Tree Count Within 100 Meters',
#     'Predicted Graduation Rate',
# ]].plot(kind='bar')
In [ ]:
# # 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}')

Predicted Metrics by Address

YOUR INTERPRETATION OF THE RESULTS

{a_table : YOUR TABLE NAME ? YOUR TABLE DESCRIPTION}

{b_geotable : YOUR MAP NAME ? YOUR MAP DESCRIPTION}

{c_image : YOUR PLOT NAME ? YOUR PLOT DESCRIPTION}