Map of tree density by district (2)
Now we have obtained the number of trees by district, we can make the map of the districts colored by the tree density.
For this, we first need to merge the number of trees in each district we calculated in the previous step (trees_by_district
) back to the districts dataset. We will use the pd.merge()
function to join two dataframes based on a common column.
Since not all districts have the same size, it is a fairer comparison to visualize the tree density: the number of trees relative to the area.
The district dataset has been pre-loaded as districts
, and the final result of the previous exercise (a DataFrame with the number of trees for each district) is available as trees_by_district
. GeoPandas has been imported as geopandas
and Pandas as pd
.
Este exercício faz parte do curso
Working with Geospatial Data in Python
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Print the first rows of the result of the previous exercise
print(trees_by_district.head())
# Merge the 'districts' and 'trees_by_district' dataframes
districts_trees = pd.merge(____)
# Inspect the result
print(districts_trees.head())