LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Analyzing US Census Data in Python

Kurs anzeigen

Anleitung zur Übung

  • 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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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()
Code bearbeiten und ausführen