ComenzarEmpieza gratis

Construct a GeoDataFrame from a DataFrame

In this exercise, you will construct a geopandas GeoDataFrame from the Nashville Public Art DataFrame. You will need to specify the CRS and define a geometry. This will get you ready to spatially join the art data and the neighborhoods data in order to discover which neighborhood has the most art.

The Nashville Public Art data has been loaded for you as art.

Este ejercicio forma parte del curso

Visualizing Geospatial Data in Python

Ver curso

Instrucciones del ejercicio

  • Print the head() of the art data.
  • construct a geometry column in the art DataFrame using the geopandas points_from_xy() method.
  • Build a GeoDataFrame using art and call it art_geo. Set crs equal to the neighborhoods.crs and set the geometry equal to the column you just created.
  • Print the type() of art_geo to verify it is a GeoDataFrame.

Ejercicio interactivo práctico

Prueba este ejercicio completando el código de muestra.

import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt

# Print the first few rows of the art DataFrame
print(art.____())

# Create a geometry column in art
art['geometry'] = gpd.____(art.lng, art.lat)

# Create a GeoDataFrame from art and verify the type
art_geo = gpd.GeoDataFrame(art, 
                           ____ = neighborhoods.crs, 
                           ____ = art.geometry)
print(type(____))
Editar y ejecutar código