pandas 熊猫数据框,按值复制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13419822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 20:29:43  来源:igfitidea点击:

pandas dataframe, copy by value

pythonpandas

提问by Andrew

I noticed a bug in my program and the reason it is happening is because it seems that pandas is copying by reference a pandas dataframe instead of by value. I know immutable objects will always be passed by reference but pandas dataframe is not immutable so I do not see why it is passing by reference. Can anyone provide some information?

我注意到我的程序中有一个错误,它发生的原因是因为Pandas似乎是通过引用Pandas数据帧而不是值来复制的。我知道不可变对象总是通过引用传递,但 Pandas 数据帧不是不可变的,所以我不明白它为什么通过引用传递。谁能提供一些信息?

Thanks! Andrew

谢谢!安德鲁

回答by Wes McKinney

All functions in Python are "pass by reference", there is no "pass by value". If you want to make an explicit copy of a pandas object, try new_frame = frame.copy().

Python中的所有函数都是“按引用传递”,没有“按值传递”。如果你想制作一个 Pandas 对象的显式副本,请尝试new_frame = frame.copy().