python - geopandas:创建的克隆会破坏父文件的属性
问题描述
我已经执行了以下代码,不幸的是,当我编辑另一个变量时,父变量数据被修改了。
代码如下:
filename="../foobar.shp" #........ import any shapefile
db_file1 = geopandas.GeoDataFrame.from_file(filename)
db_file2=db_file1 #Equating one geopandas to another,essentially creating a copy
db_file2.code=(db_file2.code*2) #Where "code" is a valid column header
print (db_file2,"\n",db_file1)
输出显示 db_file1 已被修改,即使没有做任何类似的事情。我在这里做错了什么?
解决方案
您没有复制,您将两个变量指向内存中的同一个对象。为了制作副本,您应该使用
df2 = df.copy()
推荐阅读
- keras - 深度学习 - 对给定图像是否是异常/新奇/异常值进行分类?
- algorithm - 查找二维数组中所有峰值的高效算法
- c# - 如何从字符串计算浮点值
- php - 使用 PHP 会话打开新的 android 活动
- azure-cosmosdb - Cosmos DB id 和 partitionKey 中的受限字符
- c++ - 我们可以使用 !islessgreater(float a, float b) 来检查 a==b 给定 a 和 b 都不是 nan
- django - django ORM 问题 - 注释和聚合返回不一致的值
- python - 侧边栏菜单应基于基于角色的登录 django 加载
- asp.net-mvc - 从登录 Asp.net 核心中排除自定义异常类
- kubernetes - 我的 pod 处于 Container Creating 状态,显示 TLS 握手超时