0

Is there any way to do df = df.join(df2) but using the inplace argument available in many other functions? I.e. I want to do df.join(df2, inplace=True). Of course this does not work because join does not have this argument, unlike many other functions in Pandas. How can I do this operation "inplace"?

user171780
  • 2,243
  • 1
  • 20
  • 43

1 Answers1

0

As mentioned, join does not have an inplace parameter. You will have to use df = df.join(df2).

It is also worth mentioning that inplace = True isn't actually that great to use. It provides no real benefit to performance since most functions still create copies under the hood then at the final step overwrite the reference to the new transformed copy. It also can introduce bugs when mutating original datasets and can be hard to find later down the line.

This blog post explains this really well: Why You Should Probably Never Use pandas inplace=True

In your case, even though you are reassigning the variable df to another dataframe, the original dataframe is kept intact.

eHarazi
  • 368
  • 3
  • 13