in pandas the inplace parameter make modification on the reference but I know in python data are sent by value not by reference i want to know how this is implemented or how this work
CodePudding user response:
Python’s argument passing model is neither “Pass by Value” nor “Pass by Reference” but it is “Pass by Object Reference”
When you pass a dictionary to a function and modify that dictionary inside the function, the changes will reflect on the dictionary everywhere.
However, here we are dealing with something even less ambiguous. When passing inplace=True
to a method call on a pandas
object (be it a Series
or a DataFrame
), we are simply saying: change the current object instead of getting me a new one. Method calls can modify variables of the instances on which they were called - this is independent of whether a language is "call by value" or "call by reference". The only case in which this would get tricky is if a language only had constants (think val
) and no variables (think var
) - think purely functional languages. Then, it's true - you can only return new objects and can't modify any old ones. In practice, though, even in purest of languages you can find ways to update records in-place.