Get startedGet started for free

Worker Population

In this exercise you will create a map comparing worker and residential population densities in the New York Metropolitan Area. You will use geopandas, which you saw in a previous chapter. The New York metro area county geometries are in the geopandas DataFrame geo_nyma, which is displayed in the plot window. The additional demographic info is loaded in the DataFrame nyma_counties.

pandas and geopandas are loaded using the usual aliases.

This exercise is part of the course

Analyzing US Census Data in Python

View Course

Exercise instructions

  • Merge geo_nyma with nyma_counties on columns state and county
  • Calculate worker and residential densities in square kilometers as 1000**2 times the worker and residential populations, divided by geo_nyma.area
  • Plot the residential density by setting the column parameter to the appropriate column
  • Do the same for worker density

Hands-on interactive exercise

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

# Merge population data with geopandas DataFrame
geo_nyma = pd.merge(geo_nyma, ____, ____)

# Calculate population densities
geo_nyma["worker_density"] = ____
geo_nyma["residential_density"] = ____

# Compare residential and worker density plots
fig, axes = plt.subplots(ncols=2)
geo_nyma.plot(____, cmap = "YlGnBu", ax=axes[0])
geo_nyma.plot(____, cmap = "YlGnBu", ax=axes[1])
plt.show()
Edit and Run Code