You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从dask_geopandas.GeoSeries创建仅包含几何列的dask_geopandas.GeoDataFrame?

How to create a dask_geopandas.GeoDataFrame with only a geometry column from a dask_geopandas.GeoSeries

你遇到的问题是因为dask-geopandas的API和geopandas在细节上有区别,直接用.values会得到底层的dask数组,而不是GeoSeries对象,所以构造器无法正确识别。这里有两种简单的等价实现方式:

方法1:直接使用GeoDataFrame构造器

不需要调用.values,直接把你的dask_geopandas.GeoSeries传给geometry参数即可:

import dask_geopandas as dgpd

# dgser 是已有的dask_geopandas.GeoSeries对象
dgdf = dgpd.GeoDataFrame(geometry=dgser)

方法2:使用GeoSeries的to_frame()方法

这是更简洁的方式,直接将GeoSeries转换为只包含指定列名的GeoDataFrame:

# 这里指定列名为'geometry',和默认的几何列名保持一致
dgdf = dgser.to_frame(name='geometry')

两种方法都能得到仅包含几何列的dask_geopandas.GeoDataFrame,且几何列的数据完全来自你的原始GeoSeries。

内容的提问来源于stack exchange,提问作者duff18

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 17:29:09