【发布时间】:2023-01-19 22:06:44
【问题描述】:
当我deepcopy没有“几何”列的geopandas.GeoDataFrame时,副本变成了pandas.DataFrame。为什么会这样?我查看了 Github 上的主要分支,Pandas 和 Geopandas 都没有覆盖 __deepcopy__。
import copy
import geopandas as gpd
empty = gpd.GeoDataFrame()
print("original plain:", type(empty))
print("copied plain:", type(copy.deepcopy(empty)))
geom = gpd.GeoDataFrame(columns=["geometry"])
print("original with geometry:", type(geom))
print("copied with geometry:", type(copy.deepcopy(geom)))
输出:
original plain: <class 'geopandas.geodataframe.GeoDataFrame'>
copied plain: <class 'pandas.core.frame.DataFrame'>
original with geometry: <class 'geopandas.geodataframe.GeoDataFrame'>
copied with geometry: <class 'geopandas.geodataframe.GeoDataFrame'>
【问题讨论】:
标签: python pandas geopandas deep-copy