开始使用免费开始使用

探索巴黎行政区(II)

在上一个练习中,我们使用了 GeoDataFrame 的定制版 plot() 方法,它可以对数据集中的几何对象进行简单可视化。GeoDataFrame 和 GeoSeries 可以看作是"具备空间感知"的 DataFrame 和 Series。与 pandas 的对应对象相比,它们提供了额外的空间相关方法和属性。

GeoDataFrame 的 .geometry 属性总是返回包含几何对象的那一列,类型为 GeoSeries,无论该列的实际列名是什么(默认情况下也叫 "geometry")。

另一个空间功能的示例是 area 属性,用于给出多边形的面积。

已将 GeoPandas 以 geopandas 导入,行政区数据集已作为变量 districts 提供。

本练习是课程的一部分

在 Python 中处理地理空间数据

查看课程

练习说明

  • 使用 type() 函数检查 districts 是什么类型的对象。
  • 访问 districts 这个 GeoDataFrame 的 geometry 属性,并打印该对象的类型。
  • 显示 geometry 的前 5 行。
  • 查看各行政区几何的面积。

交互式实操练习

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

# Check what kind of object districts is
print(type(____))

# Check the type of the geometry attribute
print(____)

# Inspect the first rows of the geometry
print(districts.____)

# Inspect the area of the districts
print(districts.____)
编辑并运行代码