ComenzarEmpieza gratis

Visualizing the population density

Let's get back to the districts dataset. In a previous exercise we visualized the districts with a uniform column. But often we want to show the spatial variation of a variable, and color the polygons accordingly.

In this exercise we will visualize the spatial variation of the population density within the center of Paris. For this, we will first calculate the population density by dividing the population number with the area, and add it as a new column to the dataframe.

The districts dataset is already loaded as districts, GeoPandas has been imported as geopandas and matplotlib.pyplot as plt.

Este ejercicio forma parte del curso

Working with Geospatial Data in Python

Ver curso

Instrucciones del ejercicio

  • Print the first rows of the districts dataset. Do you see the 'population' column?
  • Inspect the area of the districts's geometries.
  • Add a column 'population_density' representing the number of inhabitants per squared kilometer (Note: The area is given in squared meter, so you will need to multiply the result with 10**6).
  • Plot the districts using the 'population_density' to color the polygons.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

# Inspect the first rows of the districts dataset
print(districts.head())

# Inspect the area of the districts
print(districts.____)

# Add a population density column
districts['population_density'] = ____ / ____ * ____

# Make a plot of the districts colored by the population density
districts.____(____, legend=True)
plt.show()
Editar y ejecutar código