CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Visualizing Geospatial Data in Python

Afficher le cours

Instructions

  • Create a geometry column in permits from lat and lng.
  • Create permits_geo, a GeoDataFrame, using permits, the crs from council_districts, and the geometry from permits.
  • Use a spatial join to find permits issued within each council district. Print the first 2 rows.
  • Create permit_counts to show the count of permits within each district, using groupby() and .size(). Print permit_counts.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

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)
Modifier et exécuter le code