Wednesday, 7 December 2022

Deep dive into when you should use Inplace argument in Pandas functions and why not to use it?

Probably it's very common to use inplace argument in Pandas functions when manipulating dataframes.

Inplace is an argument used in different functions. Some functions in which inplace is used as an attributes like set_index(), dropna(), fillna(), reset_index(), drop(), replace() and many more. The default value of this attribute is False and it returns the copy of the object.

I want to know in detail when it's good practice to use inplace in pandas functions and when you shouldn't do that also, the reason for that. Can you demonstrate in examples to be a reference since this issue is very common in using pandas functions.

As Example:

df.drop(columns=[your_columns], inplace=True)

In which cases using inplace with drop is recommended. Also if some variables like list depending on the dataframe. changing it inplace will affect the result of other variables that depending on it. Another issue which is using inplace prevent method chaining on pandas dataframe.



from Deep dive into when you should use Inplace argument in Pandas functions and why not to use it?

No comments:

Post a Comment