Indexing and Selecting Data
GeoPandas inherits the standard pandas
methods for indexing/selecting data. This includes label based indexing with .loc
and integer position based indexing with .iloc
, which apply to both GeoSeries
and GeoDataFrame
objects. For more information on indexing/selecting, see the pandas documentation.
GeoPandas继承了用于索引/选择数据的标准pandas方法。 这包括使用.loc进行基于标签的索引和使用.iloc进行基于整数位置的索引,这些索引适用于GeoSeries和GeoDataFrame对象。 有关索引/选择的更多信息,请参阅pandas文档。
In addition to the standard pandas
methods, GeoPandas also provides coordinate based indexing with the cx
indexer, which slices using a bounding box. Geometries in the GeoSeries
or GeoDataFrame
that intersect the bounding box will be returned.
除了标准的pandas方法之外,GeoPandas还为cx索引器提供基于坐标的索引,cx索引器使用边界框进行切片。 将返回与边界框相交的GeoSeries或GeoDataFrame中的几何图形。
Using the world
dataset, we can use this functionality to quickly select all countries whose boundaries extend into the southern hemisphere.
使用世界数据集,我们可以使用此功能快速选择所有边界延伸到南半球的国家/地区。
In [1]: world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
In [2]: southern_world = world.cx[:, :0]
In [3]: southern_world.plot(figsize=(10, 3));