使用'='技巧复制Pandas DataFrame [英] Copy Pandas DataFrame using '=' trick
问题描述
我有两个熊猫DataFrame,sdm
.我想创建该DataFrame的副本并进行处理,后来,我想从sdm
创建另一个副本并进行其他分析.但是,当我像这样创建新的数据框时,
I have two pandas DataFrames, sdm
. I wanted to create a copy of that DataFrame and work on that and later, I want to create another copy from sdm
and work on different analysis. However, when I create a new Data Frame like this,
new_df = sdm
它将创建一个副本,但是,当我更改new_df
时,它将对我的旧DataFrame sdm
进行更改.不使用=
怎么办?
It creates a copy, however, when I alter new_df
, it makes changes to the my old DataFrame sdm
. How can I handle this without using =
?
推荐答案
python所做的工作是通过引用传递的.试试这个:
What python does is passing by reference. Try this:
new_df = sdm.copy()
我认为您应该进行更多搜索,我相信对此主题会有很多疑问!
I think you should have search more, I am sure there will be lots of questions on this topic!
这篇关于使用'='技巧复制Pandas DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!