开始使用免费开始使用

从 DataFrame 构建 GeoDataFrame

在本练习中,您将从 Nashville Public Art 的 DataFrame 构建一个 geopandas 的 GeoDataFrame。您需要指定 CRS 并定义几何列。这样就能为后续将艺术数据与社区数据进行空间连接做好准备,从而找出哪个社区拥有最多的公共艺术。

Nashville Public Art 数据已加载为 art

本练习是课程的一部分

在 Python 中可视化地理空间数据

查看课程

练习说明

  • 打印 art 数据的 head()
  • 使用 geopandaspoints_from_xy() 方法在 art DataFrame 中构建一个几何列。
  • 使用 art 构建一个 GeoDataFrame,并命名为 art_geo。将 crs 设置为 neighborhoods.crs,并将 geometry 设置为您刚刚创建的那一列。
  • 打印 art_geotype(),以验证它是一个 GeoDataFrame。

交互式实操练习

通过完成这段示例代码来试试这个练习。

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(____))
编辑并运行代码