[英]Pandas dataframe initialization changes the value of the original dataframe
Please look at the screenshot attached. 请查看所附的屏幕截图。
I created a Dataframe df then Initialized another Dataframe tesla which holds df 我创建了一个数据框df,然后初始化了另一个保存有df的数据框特斯拉
Then I perform my Manipulations on tesla and then when I check back on df 然后我在tesla上执行操作,然后在df上再次查看时
df has changed too. df也发生了变化。
Why is this happening? 为什么会这样呢?
I have been using Pandas for a long time now and haven't noticed this issue. 我已经使用Pandas很长时间了,还没有注意到这个问题。
您应该使用copy
,然后在新df中应用更改时,它不会更改原始df
tesla=df.copy()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.