Get startedGet started for free

Building a polished Geopandas choropleth

After merging the counts_df with permits_by_district, you will create a column with normalized permit_density by dividing the count of permits in each council district by the area of that council district. Then you will plot your final geopandas choropleth of the building projects in each council district.

This exercise is part of the course

Visualizing Geospatial Data in Python

View Course

Exercise instructions

  • Merge permits_by_district and counts_df on district to create districts_and_permits.
  • Using apply() and a lambda expression, calculate a new column in districts_and_permits called permit_density. Divide counts by areas.
  • Plot a choropleth of the districts_and_permits, using permit_density with the OrRd colormap, and black outlines.
  • Add axis labels (longitude and latitude) and the title provided. Show your plot.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Merge permits_by_district and counts_df
districts_and_permits = pd.merge(____, ____, on = ____)

# Create permit_density column
districts_and_permits['permit_density'] = districts_and_permits.apply(lambda row: row.____ / row.____, axis = 1)
print(districts_and_permits.head(2))

# Create choropleth plot
districts_and_permits.plot(column = ____, ____ = 'OrRd', ____ = 'black', legend = True)

# Add axis labels and title
plt.xlabel(____)
plt.ylabel(____)
plt.title('2017 Building Project Density by Council District')
plt.show()
Edit and Run Code