19

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?

Thanks! Andrew

Andrew
  • 758
  • 3
  • 9
  • 17

1 Answers1

41

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().

Wes McKinney
  • 101,437
  • 32
  • 142
  • 108
  • 1
    Note that this does not include the `frame.index` as of version 0.12. However, a fix seems to be on the way for 0.13 (as mentioned in [this related question](http://stackoverflow.com/q/17591104/2375855): GitHub Pandas [Issue 4202](http://github.com/pydata/pandas/issues/4202)) – ojdo Nov 26 '13 at 14:46