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
"?
Asked
Active
Viewed 300 times
0

user171780
- 2,243
- 1
- 20
- 43
-
There is no way to join this in place afaik. `df = df.join(df2)` is your best bet. – Jeremy Savage Oct 08 '22 at 18:57
-
One alternative method here: [Pandas left join in place](https://stackoverflow.com/questions/50849102/pandas-left-join-in-place). – sj95126 Oct 08 '22 at 19:02
1 Answers
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