Planting Trees for The Big Apple to Grow
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    Which tree species should the city plant?

    📖 Background

    You work for a nonprofit organization advising the planning department on ways to improve the quantity and quality of trees in New York City. The urban design team believes tree size (using trunk diameter as a proxy for size) and health are the most desirable characteristics of city trees.

    The city would like to learn more about which tree species are the best choice to plant on the streets of Manhattan.

    💾 The data

    The team has provided access to the 2015 tree census and geographical information on New York City neighborhoods (trees, neighborhoods):

    Tree Census
    • "tree_id" - Unique id of each tree.
    • "tree_dbh" - The diameter of the tree in inches measured at 54 inches above the ground.
    • "curb_loc" - Location of the tree bed in relation to the curb. Either along the curb (OnCurb) or offset from the curb (OffsetFromCurb).
    • "spc_common" - Common name for the species.
    • "status" - Indicates whether the tree is alive or standing dead.
    • "health" - Indication of the tree's health (Good, Fair, and Poor).
    • "root_stone" - Indicates the presence of a root problem caused by paving stones in the tree bed.
    • "root_grate" - Indicates the presence of a root problem caused by metal grates in the tree bed.
    • "root_other" - Indicates the presence of other root problems.
    • "trunk_wire" - Indicates the presence of a trunk problem caused by wires or rope wrapped around the trunk.
    • "trnk_light" - Indicates the presence of a trunk problem caused by lighting installed on the tree.
    • "trnk_other" - Indicates the presence of other trunk problems.
    • "brch_light" - Indicates the presence of a branch problem caused by lights or wires in the branches.
    • "brch_shoe" - Indicates the presence of a branch problem caused by shoes in the branches.
    • "brch_other" - Indicates the presence of other branch problems.
    • "postcode" - Five-digit zip code where the tree is located.
    • "nta" - Neighborhood Tabulation Area (NTA) code from the 2010 US Census for the tree.
    • "nta_name" - Neighborhood name.
    • "latitude" - Latitude of the tree, in decimal degrees.
    • "longitude" - Longitude of the tree, in decimal degrees.
    Neighborhoods' geographical information
    • "ntacode" - NTA code (matches Tree Census information).
    • "ntaname" - Neighborhood name (matches Tree Census information).
    • "geometry" - Polygon that defines the neighborhood.

    Tree census and neighborhood information from the City of New York NYC Open Data.

    Dependencies and Importing Data

    import pandas as pd
    import geopandas as gpd
    trees = pd.read_csv('data/trees.csv')
    trees
    neighborhoods = gpd.read_file('data/nta.shp')
    neighborhoods

    Initial Data Exploration

    I prefer to begin by getting familiar with the data. Above we can get a glimpse at the number of rows, column names, and some frequent values. I also want to know the type of each dataframe and the datatypes of attributes in each. This helps to avoid mistakes when working with them. It is important to notice that we can join the dataframes using "nta" or "nta_name" and also that we have a GeoDataFrame available to help us create geographic plots.

    trees.dtypes
    neighborhoods.dtypes
    type(trees)
    type(neighborhoods)
    neighborhoods.boroname.unique()

    1. What are the most common tree species in Manhattan?

    The trees dataframe includes each tree in New York City, its species, and the neighborhood it is located in, but it does not contain borough information. In order to determine what is the most common tree species in Manhattan, we must first determine which neighborhoods are in Manhattan, and then which trees are in those neighborhoods. We can achieve this by: 1. Filter the neighborhood dataframe to only include Manhattan neighborhoods 2. Filter the trees dataframe based on having a "ntacode" which corresponds to a Manhattan neighborhood 3. Group the trees by species and count the number in each group

    manhat_neighborhoods = neighborhoods[neighborhoods.boroname == "Manhattan"]
    manhat_neighborhoods