Finding counts from a spatial join
You will be using a dataset of the building permits issued in Nashville during 2017. This DataFrame, called permits, has been pre-loaded for you, along with the council_districts GeoDataFrame.
Este exercício faz parte do curso
Visualizing Geospatial Data in Python
Instruções do exercício
- Create a
geometrycolumn inpermitsfromlatandlng. - Create
permits_geo, a GeoDataFrame, usingpermits, the crs fromcouncil_districts, and thegeometryfrompermits. - Use a spatial join to find permits issued
withineach council district. Print the first 2 rows. - Create
permit_countsto show the count of permits within each district, usinggroupby()and.size(). Printpermit_counts.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
import geopandas as gpd
# Create a geometry column in permits from lat and lng
permits[____] = gpd.points_from_xy(____.____ , ____.____)
# Build a GeoDataFrame: permits_geo
permits_geo = gpd.GeoDataFrame(____, crs = ____.crs, geometry = ____.geometry)
# Spatial join of permits_geo and council_districts
permits_by_district = gpd.____(permits_geo, council_districts, predicate = ____)
print(permits_by_district.head(2))
# Create permit_counts
permit_counts = permits_by_district.groupby([____]).____()
print(permit_counts)