{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 向量数据的属性和索引\n", "\n", "每个 GeoSeries 都可以包含任何几何类型(例如点、线、多边形),并拥有 `GeoSeries.crs` 属性,它存储关于投影(projection)的信息(`crs` 代表坐标参考系(Coordinate Reference System))。因此,`GeoDataFrame` 中的每个 `GeoSeries` 可以在不同的投影中,例如,允许您在不同的 CRS 中拥有相同几何图形的多个版本。\n", "\n", "## 创建新属性\n", "\n", "最基本的运算之一是创建新属性。举个例子,想看看世界人口以百万为单位。可以从现有的数据列 `pop_est` 开始。从查看列名开始:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['pop_est', 'continent', 'name', 'iso_a3', 'gdp_md_est', 'geometry'], dtype='object')" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import geopandas\n", "world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))\n", "world.columns" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "然后,可以根据列名进行基本运算。这里创建新列 `m_pop_est`:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | pop_est | \n", "continent | \n", "name | \n", "iso_a3 | \n", "gdp_md_est | \n", "geometry | \n", "m_pop_est | \n", "
---|---|---|---|---|---|---|---|
0 | \n", "889953.0 | \n", "Oceania | \n", "Fiji | \n", "FJI | \n", "5496 | \n", "MULTIPOLYGON (((180.00000 -16.06713, 180.00000... | \n", "0.889953 | \n", "
1 | \n", "58005463.0 | \n", "Africa | \n", "Tanzania | \n", "TZA | \n", "63177 | \n", "POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... | \n", "58.005463 | \n", "