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

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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: GitHub Pandas Issue 4202)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.