I have a pandas dataframe "df" on which I apply several functions. I do not want to change the values of the original dataframe. All my functions look like this:
def func(x):
# do some stuff with x
return x
y = func(x=df)
I do not refer to the df variable within the function. But the variable get changed anyway. Can someone explain to me why that's the case and how to avoid it?
dfis mutable. You're passing a reference todfto the method which is mutating it. If you want to keep the original intact, send in a copy ofdf