Can you use apply() in Pandas to update in-place?


#1

Question

Can we utilize the apply() method in Pandas to update a dataframe in-place?

Answer

No, unlike other methods that update the dataframe for which you can specify in-place, such as

df.drop(['A'], inplace=True)
df.rename({'B' : 'C'}, inplace=True)

using the apply() method does not have the parameter for inplace.

As a result, whenever you use apply() on a dataframe, if you wish to update the dataframe, then you must reassign it, for example:

df = df.apply(my_lambda)