In [1]:
import geopandas as gpd
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from shapely.geometry import Point

%matplotlib inline

In [2]:
df = gpd.read_file('../data/external/tree-canopy.geojson')

In [3]:
df.columns


Out[3]:
Index(['address', 'block_id', 'boro_ct', 'borocode', 'boroname', 'brch_light',
       'brch_other', 'brch_shoe', 'cb_num', 'cncldist', 'created_at',
       'curb_loc', 'geometry', 'guards', 'health', 'latitude', 'longitude',
       'nta', 'nta_name', 'root_grate', 'root_other', 'root_stone', 'sidewalk',
       'spc_common', 'spc_latin', 'st_assem', 'st_senate', 'state', 'status',
       'steward', 'stump_diam', 'tree_dbh', 'tree_id', 'trnk_light',
       'trnk_other', 'trunk_wire', 'user_type', 'x_sp', 'y_sp', 'zip_city',
       'zipcode'],
      dtype='object')

In [4]:
df.head()


Out[4]:
address block_id boro_ct borocode boroname brch_light brch_other brch_shoe cb_num cncldist ... tree_dbh tree_id trnk_light trnk_other trunk_wire user_type x_sp y_sp zip_city zipcode
0 45 DUPONT STREET 216486 3056300 3 Brooklyn No No No 301 33 ... 4 101233 No No No Volunteer 995754.899878 207355.752989 Brooklyn 11222
1 2 CLAY STREET 216486 3056300 3 Brooklyn No No No 301 33 ... 4 101234 No No No Volunteer 995747.63677 207412.792245 Brooklyn 11222
2 2 CLAY STREET 216486 3056300 3 Brooklyn No No No 301 33 ... 4 101235 No No No Volunteer 995743.885137 207442.254128 Brooklyn 11222
3 237 FRANKLIN STREET 216291 3056300 3 Brooklyn Yes No No 301 33 ... 15 101400 No No No Volunteer 995653.777377 207228.768335 Brooklyn 11222
4 237 FRANKLIN STREET 216291 3056300 3 Brooklyn Yes No No 301 33 ... 18 101401 No No No Volunteer 995616.258095 207224.169263 Brooklyn 11222

5 rows × 41 columns


In [5]:
# Keep only the relevant columns
df = df.loc[:, ["block_id", "tree_dbh", "status", "health", "spc_latin", 
                "spc_common", "sidewalk", "geometry", "tree_id"]]

In [6]:
# There are dead and stumped trees in the data set!
print ("Dead:", len(df[df.status == "Dead"]))
print ("Stump:", len(df[df.status == "Stump"]))


Dead: 10376
Stump: 11469

In [7]:
# Keep only trees that are alive 
df = df[df.status == "Alive"]

In [8]:
# Make sure we're using the correct projection
df = df.to_crs({'init' :'epsg:4326'})

In [9]:
df.head(3)


Out[9]:
block_id tree_dbh status health spc_latin spc_common sidewalk geometry tree_id
0 216486 4 Alive Good Quercus bicolor Swamp White Oak NoDamage POINT (-73.95848582835121 40.7358127696309) 101233
1 216486 4 Alive Good Quercus bicolor Swamp White Oak NoDamage POINT (-73.95851193899931 40.73596933773587) 101234
2 216486 4 Alive Good Quercus bicolor Swamp White Oak NoDamage POINT (-73.95852542605115 40.7360502081988) 101235

Notes on Columns

From data reference PDF

tree_dbh

Diameter of the tree, measured at approximately 54" / 137cm above the ground. Data was collected for both living and dead trees; for stumps, use stump_diam

Because standard measuring tapes are more accessible than forestry-specific measuring tapes designed to measure diameter, users originally measured tree circumference in the field. To better match other forestry datasets, this circumference value was subsequently divided by 3.14159 to transform it to diameter. Both the field measurement and processed value were rounded to the nearest whole inch.

health

Indicates the user's perception of tree health.


In [9]:
# Make tree diameter an integer
df.tree_dbh = df.tree_dbh.astype("int64")

In [10]:
df.describe()


Out[10]:
tree_dbh
count 446496.000000
mean 10.782509
std 8.043712
min 0.000000
25% 4.000000
50% 9.000000
75% 15.000000
max 318.000000

In [11]:
len(df[df["tree_dbh"] < 50])


Out[11]:
446246

In [12]:
df[df["tree_dbh"] > 100]


Out[12]:
block_id tree_dbh status health spc_latin spc_common sidewalk geometry tree_id
744 216298 151 Alive Good Platanus x acerifolia London Planetree NoDamage POINT (-73.94963654163899 40.73360178269525) 150206
4745 503571 132 Alive Good Quercus palustris Pin Oak Damage POINT (-73.92214721500579 40.84101218187434) 4934
12309 315586 140 Alive Fair Acer platanoides 'Crimson King' Crimson King Maple NoDamage POINT (-73.82890269636783 40.78957015294017) 14414
27323 336132 149 Alive Good Acer platanoides Norway Maple NoDamage POINT (-73.71199233472572 40.74215819426818) 32503
33440 203212 170 Alive Good Platanus x acerifolia London Planetree Damage POINT (-74.03402831453573 40.61254217713028) 40115
42645 414909 131 Alive Good Prunus Cherry NoDamage POINT (-74.14700367458741 40.56092321377076) 51675
50941 219890 110 Alive Good Quercus phellos Willow Oak NoDamage POINT (-73.98127871850185 40.70137097264522) 62298
50942 219890 103 Alive Good Quercus phellos Willow Oak NoDamage POINT (-73.98143797656377 40.70137623401526) 62299
64214 340997 168 Alive Good Acer saccharinum Silver Maple Damage POINT (-73.88477731045042 40.75195816002473) 78148
94995 409043 123 Alive Good Pyrus calleryana Callery Pear Damage POINT (-74.15677389502299 40.58118662295067) 114413
116346 345503 141 Alive Fair Styphnolobium japonicum Sophora NoDamage POINT (-73.91891883237193 40.70770357892945) 139935
124932 216298 151 Alive Good Platanus x acerifolia London Planetree NoDamage POINT (-73.94963654163899 40.73360178269525) 150206
147662 105392 199 Alive Good Quercus phellos Willow Oak Damage POINT (-73.98149568238884 40.73802749847806) 176434
150167 349326 280 Alive Fair Quercus palustris Pin Oak Damage POINT (-73.85075191722574 40.73407357725404) 179366
154816 504315 105 Alive Fair Ginkgo biloba Ginkgo Damage POINT (-73.89995266828473 40.85570431507499) 184879
176467 415127 122 Alive Good Quercus palustris Pin Oak Damage POINT (-74.11595934608093 40.56237936437955) 209349
181319 323383 177 Alive Fair Robinia pseudoacacia Black Locust NoDamage POINT (-73.76258496912143 40.76634288234309) 214532
181321 323383 281 Alive Good Platanus x acerifolia London Planetree NoDamage POINT (-73.7625384873382 40.76614689562982) 214534
181736 515054 169 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage POINT (-73.84720553041984 40.89488599898038) 215075
186466 345508 109 Alive Poor Acer platanoides Norway Maple Damage POINT (-73.91583112779581 40.70900168234769) 220376
205995 331501 120 Alive Good Pyrus calleryana Callery Pear NoDamage POINT (-73.76094141242042 40.66553573925207) 244676
230998 402196 255 Alive Good Platanus x acerifolia London Planetree Damage POINT (-74.10436250201329 40.62719847201268) 278078
238176 402678 234 Alive Good Pyrus calleryana Callery Pear NoDamage POINT (-74.1043525815932 40.63216535045648) 287234
252840 109033 228 Alive Fair Pyrus calleryana Callery Pear NoDamage POINT (-73.94811557539715 40.80217803866228) 304388
255936 230458 204 Alive Good Tilia cordata Little-Leaf Linden Damage POINT (-73.9545715871638 40.63631586635876) 309065
258571 108838 109 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis Damage POINT (-73.94326132079063 40.83099428303229) 312202
258881 110893 120 Alive Good Quercus phellos Willow Oak NoDamage POINT (-73.93792184501238 40.84375619050143) 312545
279161 412645 128 Alive Good Liquidambar styraciflua Sweetgum NoDamage POINT (-74.21513526248653 40.54514134663208) 337040
291821 411769 143 Alive Good Acer platanoides 'Crimson King' Crimson King Maple NoDamage POINT (-74.19630255726101 40.54049402483789) 351433
293203 412477 102 Alive Fair Liquidambar styraciflua Sweetgum NoDamage POINT (-74.19808054984397 40.54230932994701) 353016
302650 512207 204 Alive Good Acer platanoides Norway Maple NoDamage POINT (-73.83819880422423 40.85876665173129) 363589
323984 225524 159 Alive Fair Fraxinus pennsylvanica Green Ash NoDamage POINT (-73.97824689356895 40.65908927853423) 389470
325738 502971 291 Alive Fair Prunus Cherry NoDamage POINT (-73.91267354489182 40.82811397848261) 391542
331379 500877 149 Alive Good Ulmus pumila Siberian Elm Damage POINT (-73.90680241518139 40.81896424864818) 397670
336810 227982 175 Alive Poor Acer platanoides Norway Maple NoDamage POINT (-73.97425709622421 40.62626157447485) 403744
340869 410345 298 Alive Good Pyrus calleryana Callery Pear NoDamage POINT (-74.2125325097725 40.51850794909242) 409369
348289 202962 318 Alive Good Platanus x acerifolia London Planetree NoDamage POINT (-73.86964112633321 40.68836584931302) 418433
354617 307686 131 Alive Good Fraxinus pennsylvanica Green Ash NoDamage POINT (-73.86266200082441 40.67920402798998) 426327
354805 202420 142 Alive Good Tilia cordata Little-Leaf Linden NoDamage POINT (-73.86463238639334 40.68041785072293) 426541
355120 200027 141 Alive Good Tilia cordata Little-Leaf Linden NoDamage POINT (-73.88067048784831 40.64708701854034) 426892
361419 214944 183 Alive Good Platanus x acerifolia London Planetree Damage POINT (-73.88820151214408 40.64315352799438) 434044
369537 200089 209 Alive Good Zelkova serrata Japanese Zelkova Damage POINT (-73.88907058165442 40.65507955293081) 443491
398436 602575 318 Alive Good Quercus palustris Pin Oak NoDamage POINT (-73.94306676395681 40.85087931360806) 476317
418321 407837 250 Alive Good Platanus x acerifolia London Planetree NoDamage POINT (-74.16657236050897 40.59998974973866) 498910
418322 407837 154 Alive Good Acer rubrum Red Maple NoDamage POINT (-74.16654912290724 40.60010921449845) 498911
419349 413239 147 Alive Poor Pyrus calleryana Callery Pear NoDamage POINT (-74.17271185922384 40.55350188039718) 500075
425385 508209 106 Alive Good Ginkgo biloba Ginkgo NoDamage POINT (-73.86947785217113 40.82824548961173) 506458
451247 338387 261 Alive Good Pyrus calleryana Callery Pear NoDamage POINT (-73.81628973333295 40.58604189844519) 535083
459136 339743 106 Alive Good Zelkova serrata Japanese Zelkova NoDamage POINT (-73.84825201463021 40.58158416122568) 545047
459668 338133 109 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis Damage POINT (-73.84931009215855 40.57837830682958) 545946
460907 0 165 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage POINT (-73.85820046054852 40.57815578355512) 548390

In [14]:
df[df["tree_dbh"] < 40].tree_dbh.value_counts(sort=False).plot(kind="bar")


Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x1464b8e80>

The most common tree trunk size is 4.

Assumptions

  • Increase in number of trees is a benefit. Every new tree within the radius of the bike station should increase score.
  • Any tree is valuable, even in poor condition. No negative scores.
  • There is a diminishing return in increasing tree size.

What is the relative benefit of increasing size of trees? Does a tree twice as large bring twice as much value to publice space? Or do trees have a diminishing return on size?


In [13]:
tree_size_counts = df.tree_dbh.value_counts(sort=False)

In [14]:
df["size_score"] = np.sqrt(1 + df.tree_dbh)

In [15]:
df.size_score.hist(bins=30)


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x1479b1a20>

Much better distrbution. We'll use this for the score.


In [16]:
df.health.value_counts(sort=False).plot(kind="bar")


Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x147a780b8>

In [17]:
# One tree does not have health status. Remove it.
df[pd.isnull(df.health)]


Out[17]:
block_id tree_dbh status health spc_latin spc_common sidewalk geometry tree_id size_score
206251 413012 16 Alive None Fraxinus pennsylvanica Green Ash Damage POINT (-74.21641202587655 40.54859739520807) 245041 4.123106

In [18]:
df = df[~pd.isnull(df.health)]

Thoughts

Bad health should cause a penalty, good health should simply be 100%.

  • Good: 100%
  • Fair: 80%
  • Poor: 60%

In [19]:
def define_health(x):
    if x == "Good":
        return 1.0
    elif x == "Fair":
        return 0.8
    elif x == "Poor":
        return 0.6

df["health_multiplier"] = df.health.map(define_health)

In [20]:
df["score"] = df.health_multiplier * df.size_score

In [21]:
df.score.hist(bins=60)


Out[21]:
<matplotlib.axes._subplots.AxesSubplot at 0x147b54908>

In [22]:
df.describe()


Out[22]:
tree_dbh size_score health_multiplier score
count 446495.000000 446495.000000 446495.000000 446495.000000
mean 10.782497 3.257814 0.948009 3.096809
std 8.043718 1.081271 0.107167 1.110327
min 0.000000 1.000000 0.600000 0.600000
25% 4.000000 2.236068 1.000000 2.236068
50% 9.000000 3.162278 1.000000 3.000000
75% 15.000000 4.000000 1.000000 3.741657
max 318.000000 17.860571 1.000000 17.860571

The equation for the tree score is as follow:

$$ S = h \sqrt{1 + \oslash_{tree}} $$

$h$ being the health multiplier, from 0.6 to 1.0 depending on the health of the tree.
$\oslash_{tree}$ being the diameter of the tree.


In [ ]:
df.to_csv('../data/interim/tree-scores.csv')

Merge Into CSV


In [23]:
# Merge into stations
stations = pd.read_csv('../data/processed/stations.csv')

In [24]:
# Convert stations csv into buffer polygons
geometry = gpd.GeoSeries([Point(xy) for xy in zip(stations.Longitude, stations.Latitude)])
geometry = geometry.buffer(.0005)

geo_stations = gpd.GeoDataFrame(stations, geometry=geometry)
geo_stations.crs = {'init' :'epsg:4326'}
geo_stations.head()
geo_stations.to_file('../data/interim/geo_stations')

In [25]:
# Merge street quality data with citibike stations using Geopandas Spatial Merge
station_df = gpd.sjoin(geo_stations, df, how="left", op='intersects')

In [31]:



Out[31]:
0        1705.0
0      289503.0
0      289504.0
0      289596.0
0      289597.0
0      289598.0
0      323435.0
1       23453.0
1       63578.0
1      226572.0
2      230987.0
2      230988.0
2      230991.0
2      230992.0
2      230979.0
2      230980.0
2      230981.0
2      230983.0
2      230984.0
2      230985.0
2      230986.0
4       36636.0
4       36689.0
4       36637.0
4       36688.0
4       36638.0
4       36687.0
4       36686.0
4       36639.0
4       36685.0
         ...   
662     74230.0
662     74231.0
662    376605.0
662    376606.0
662    376607.0
662    376608.0
662    376609.0
662    376610.0
662    376611.0
662    376612.0
662    376613.0
662    376614.0
662    376615.0
662    376616.0
662    376617.0
662    376618.0
662    380950.0
662    380951.0
662    380952.0
662    380953.0
662    380954.0
663    159402.0
663    159401.0
663    159324.0
663    159325.0
663    167235.0
663    247214.0
663    167236.0
663    167237.0
663    247213.0
Name: index_right, dtype: float64

In [40]:
# Save for Map
df.loc[station_df.index_right.dropna().unique(), :].to_csv("../data/map/trees.csv")

In [15]:
station_df


Out[15]:
Station_id Station_Name Location Latitude Longitude geometry index_right block_id tree_dbh status health spc_latin spc_common sidewalk
0 72 W 52 St & 11 Ave W 52 St & 11 Ave 40.767272 -73.993929 POLYGON ((-73.99342888 40.76727216, -73.993431... 1705.0 104056 10.0 Alive Good Ginkgo biloba Ginkgo NoDamage
0 72 W 52 St & 11 Ave W 52 St & 11 Ave 40.767272 -73.993929 POLYGON ((-73.99342888 40.76727216, -73.993431... 289503.0 104038 5.0 Alive Fair Quercus velutina Black Oak NoDamage
0 72 W 52 St & 11 Ave W 52 St & 11 Ave 40.767272 -73.993929 POLYGON ((-73.99342888 40.76727216, -73.993431... 289504.0 104038 5.0 Alive Fair Quercus velutina Black Oak NoDamage
0 72 W 52 St & 11 Ave W 52 St & 11 Ave 40.767272 -73.993929 POLYGON ((-73.99342888 40.76727216, -73.993431... 289596.0 104051 7.0 Alive Good Ginkgo biloba Ginkgo NoDamage
0 72 W 52 St & 11 Ave W 52 St & 11 Ave 40.767272 -73.993929 POLYGON ((-73.99342888 40.76727216, -73.993431... 289597.0 104051 4.0 Alive Good Ginkgo biloba Ginkgo NoDamage
0 72 W 52 St & 11 Ave W 52 St & 11 Ave 40.767272 -73.993929 POLYGON ((-73.99342888 40.76727216, -73.993431... 289598.0 104051 4.0 Alive Good Ginkgo biloba Ginkgo NoDamage
0 72 W 52 St & 11 Ave W 52 St & 11 Ave 40.767272 -73.993929 POLYGON ((-73.99342888 40.76727216, -73.993431... 323435.0 104052 7.0 Alive Good Pyrus calleryana Callery Pear NoDamage
1 79 Franklin St & W Broadway Franklin St & W Broadway 40.719116 -74.006667 POLYGON ((-74.00616660999999 40.71911552, -74.... 23453.0 100715 6.0 Alive Good Styphnolobium japonicum Sophora NoDamage
1 79 Franklin St & W Broadway Franklin St & W Broadway 40.719116 -74.006667 POLYGON ((-74.00616660999999 40.71911552, -74.... 63578.0 100741 11.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis Damage
1 79 Franklin St & W Broadway Franklin St & W Broadway 40.719116 -74.006667 POLYGON ((-74.00616660999999 40.71911552, -74.... 226572.0 100676 11.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis Damage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230987.0 102428 14.0 Alive Fair Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230988.0 102428 14.0 Alive Fair Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230991.0 102429 14.0 Alive Fair Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230992.0 102429 12.0 Alive Fair Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230979.0 103316 12.0 Alive Fair Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230980.0 103316 13.0 Alive Good Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230981.0 102428 15.0 Alive Good Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230983.0 102428 11.0 Alive Fair Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230984.0 102428 10.0 Alive Fair Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230985.0 102428 13.0 Alive Good Ulmus americana American Elm NoDamage
2 82 St James Pl & Pearl St St James Pl & Pearl St 40.711174 -74.000165 POLYGON ((-73.99966544999999 40.71117416, -73.... 230986.0 102428 14.0 Alive Fair Ulmus americana American Elm NoDamage
3 83 Atlantic Ave & Fort Greene Pl Atlantic Ave & Fort Greene Pl 40.683826 -73.976323 POLYGON ((-73.97582328 40.68382604, -73.975825... NaN NaN NaN NaN NaN NaN NaN NaN
4 116 W 17 St & 8 Ave W 17 St & 8 Ave 40.741776 -74.001497 POLYGON ((-74.00099745999999 40.74177603, -74.... 36636.0 103492 16.0 Alive Good Platanus x acerifolia London Planetree NoDamage
4 116 W 17 St & 8 Ave W 17 St & 8 Ave 40.741776 -74.001497 POLYGON ((-74.00099745999999 40.74177603, -74.... 36689.0 103487 16.0 Alive Good Platanus x acerifolia London Planetree NoDamage
4 116 W 17 St & 8 Ave W 17 St & 8 Ave 40.741776 -74.001497 POLYGON ((-74.00099745999999 40.74177603, -74.... 36637.0 103492 15.0 Alive Good Platanus x acerifolia London Planetree NoDamage
4 116 W 17 St & 8 Ave W 17 St & 8 Ave 40.741776 -74.001497 POLYGON ((-74.00099745999999 40.74177603, -74.... 36688.0 103487 6.0 Alive Fair Quercus palustris Pin Oak Damage
4 116 W 17 St & 8 Ave W 17 St & 8 Ave 40.741776 -74.001497 POLYGON ((-74.00099745999999 40.74177603, -74.... 36638.0 103492 16.0 Alive Good Platanus x acerifolia London Planetree NoDamage
4 116 W 17 St & 8 Ave W 17 St & 8 Ave 40.741776 -74.001497 POLYGON ((-74.00099745999999 40.74177603, -74.... 36687.0 103487 7.0 Alive Good Quercus palustris Pin Oak NoDamage
4 116 W 17 St & 8 Ave W 17 St & 8 Ave 40.741776 -74.001497 POLYGON ((-74.00099745999999 40.74177603, -74.... 36686.0 103487 7.0 Alive Good Zelkova serrata Japanese Zelkova NoDamage
4 116 W 17 St & 8 Ave W 17 St & 8 Ave 40.741776 -74.001497 POLYGON ((-74.00099745999999 40.74177603, -74.... 36639.0 103492 9.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
661 3434 W 88 St & West End Ave W 88 St & West End Ave 40.790254 -73.977183 POLYGON ((-73.97668340158461 40.79025417330418... 168276.0 106629 12.0 Alive Good Quercus palustris Pin Oak NoDamage
661 3434 W 88 St & West End Ave W 88 St & West End Ave 40.790254 -73.977183 POLYGON ((-73.97668340158461 40.79025417330418... 168308.0 106615 7.0 Alive Good Quercus palustris Pin Oak NoDamage
661 3434 W 88 St & West End Ave W 88 St & West End Ave 40.790254 -73.977183 POLYGON ((-73.97668340158461 40.79025417330418... 168309.0 106615 10.0 Alive Good Quercus palustris Pin Oak NoDamage
661 3434 W 88 St & West End Ave W 88 St & West End Ave 40.790254 -73.977183 POLYGON ((-73.97668340158461 40.79025417330418... 165831.0 106638 13.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
661 3434 W 88 St & West End Ave W 88 St & West End Ave 40.790254 -73.977183 POLYGON ((-73.97668340158461 40.79025417330418... 165830.0 106631 13.0 Alive Good Ginkgo biloba Ginkgo NoDamage
661 3434 W 88 St & West End Ave W 88 St & West End Ave 40.790254 -73.977183 POLYGON ((-73.97668340158461 40.79025417330418... 165829.0 106631 11.0 Alive Good Ginkgo biloba Ginkgo NoDamage
662 3435 Grand St & Elizabeth St Grand St & Elizabeth St 40.718822 -73.995960 POLYGON ((-73.99545999999999 40.718822, -73.99... 120711.0 101078 4.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
662 3435 Grand St & Elizabeth St Grand St & Elizabeth St 40.718822 -73.995960 POLYGON ((-73.99545999999999 40.718822, -73.99... 120693.0 101050 3.0 Alive Fair Quercus palustris Pin Oak NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 227711.0 100798 10.0 Alive Poor Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 227710.0 100798 9.0 Alive Poor Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 227712.0 100798 13.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 227950.0 100794 7.0 Alive Good Koelreuteria paniculata Golden Raintree Damage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 227986.0 100802 4.0 Alive Good Quercus rubra Northern Red Oak NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 227987.0 100802 4.0 Alive Good Quercus imbricaria Shingle Oak NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228537.0 100795 15.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228538.0 100795 5.0 Alive Fair Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228539.0 100795 5.0 Alive Poor Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228540.0 100795 9.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228541.0 100795 9.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228542.0 100795 9.0 Alive Fair Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228543.0 100795 11.0 Alive Fair Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228544.0 100795 9.0 Alive Poor Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228545.0 100795 5.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228546.0 100795 12.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228547.0 100795 5.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228549.0 100795 4.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228550.0 100795 13.0 Alive Good Gleditsia triacanthos var. inermis Honeylocust var. inermis NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228589.0 100805 4.0 Alive Fair Ginkgo biloba Ginkgo NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 228590.0 100805 4.0 Alive Fair Ginkgo biloba Ginkgo NoDamage
663 3436 Greenwich St & Hubert St Greenwich St & Hubert St 40.721319 -74.010065 POLYGON ((-74.00956499999999 40.721319, -74.00... 229144.0 100804 4.0 Alive Good Ginkgo biloba Ginkgo NoDamage

6975 rows × 14 columns


In [138]:
# Create new dataframe with summed score
station_scores = pd.DataFrame()

station_scores["score"] = station_df.groupby(['Station_id']).score.sum()
station_scores["score_mean"] = station_df.groupby(['Station_id']).score.mean()
station_scores["tree_count"] = station_df.groupby(['Station_id']).score.count()
station_scores["station_id"] = station_df.groupby(['Station_id']).score.mean().index

station_scores.fillna(0.0, inplace=True)

In [139]:
station_scores.head(3)


Out[139]:
score score_mean tree_count station_id
Station_id
72 17.364799 2.480686 7 72
79 9.573955 3.191318 3 79
82 35.070325 3.188211 11 82

In [141]:
station_scores.describe()


Out[141]:
score score_mean tree_count station_id
count 664.000000 664.000000 664.000000 664.000000
mean 30.308350 2.420123 10.346386 1938.709337
std 24.056091 1.180938 7.720449 1418.574359
min 0.000000 0.000000 0.000000 72.000000
25% 10.029243 2.165563 4.000000 397.750000
50% 27.883442 2.722640 10.000000 3063.500000
75% 44.892552 3.158382 16.000000 3259.250000
max 130.979643 5.194789 40.000000 3436.000000

In [142]:
# Histogram of scores
station_scores.score.hist(bins=50)


Out[142]:
<matplotlib.axes._subplots.AxesSubplot at 0x139378240>

In [151]:
# Histogram of tree counts
station_scores.tree_count.hist(bins=20)


Out[151]:
<matplotlib.axes._subplots.AxesSubplot at 0x139523860>

In [155]:
# Histogram of mean tree score per station
station_scores.score_mean.hist(bins=40)


Out[155]:
<matplotlib.axes._subplots.AxesSubplot at 0x13952def0>

In [158]:
zero_stations = len(station_scores[station_scores.score == 0])
print("Number of stations without trees:", str(zero_stations))


Number of stations without trees: 105

In [160]:
# Save to CSV
station_scores.to_csv("../data/processed/tree-canopy.csv")