pandas 数据框,按值复制 [英] pandas dataframe, copy by value
问题描述
我注意到程序中的一个错误,并且发生此错误的原因是因为熊猫似乎是通过引用而不是按值来复制熊猫数据框.我知道不可变对象将始终通过引用传递,但pandas数据帧不是不可变的,因此我不明白为什么它通过引用传递.谁能提供一些信息?
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?
谢谢! 安德鲁
推荐答案
Python中的所有函数都是按引用传递",没有按值传递".如果要显式复制熊猫对象,请尝试new_frame = frame.copy()
.
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()
.
这篇关于 pandas 数据框,按值复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!