What does inplace mean in Pandas?

01 Jun, 2022
In this article, we will see Inplace in pandas. 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.
Here we are using fillna() methods.
Syntax: dataframe.fillna(dataframe.mean(), inplace = False)  
Let’s understand this method with step-wise implementation:
Step 1. First, we import all the required libraries.
Python3
# import required moduleimport pandas as pd
Step 2.Creating dataframe.
Python3
# creating dataframedataframe = pd.DataFrame({'Name':['Shobhit','vaibhav',                                'vimal','Sourabh'],                                                 'Class':[11,12,10,9],                        'Age':[18,20,21,17]}) # Checking created dataframedisplay(dataframe)
  Output : 
Step 3.To see the inplace use we are going to use the rename function where we are renaming “Name” Column to “FirstName”. 
 In this step, We will not use inplace in our code.
Python3
# without using inplace renaming the columnnew_data = dataframe.rename(columns = {'Name':'FirstName'}) # check new_datadisplay(new_data)
Output :
We can clearly see that there are no changes in the original dataframe. Through this, we conclude that the default value of inplace is False.
Now in this step, we will use inplace with False value.
Python3
# putting inplace=Falsenew_data_2 = dataframe.rename(columns = {'Name':'FirstName'},                            inplace = False) #check new_data_2display(new_data_2)
Output :  
Again we can clearly see that there are no changes in the original dataset.
At last, we are putting inplace value equal to True.      
Python3
# Putting Inplace=Truedataframe.rename(columns = {'Name':'FirstName'},                 inplace = True)  # check whether dataframe is modified or notprint(dataframe)
Output :
Finally, we can see that the original dataframe columns have been modified from “Name” to “FirstName”.
Below is the complete program based on the above approach :
Python3
# importing pandasimport pandas as pd # creating dataframedataframe=pd.DataFrame({'Name':['Shobhit','Vaibhav',                                'Vimal','Sourabh'],                                                 'Class':[11,12,10,9],                        'Age':[18,20,21,17]}) # Checking created dataframe# copied dataframedisplay(dataframe) # without using inplace renaming the columnnew_data = dataframe.rename(columns = {'Name':'FirstName'}) # Copied dataframedisplay(new_data)  # checking whether dataframe is modified or not# Original dataframedisplay(dataframe) # putting inplace=Falsenew_data_2 = dataframe.rename(columns = {'Name':'FirstName'},                              inplace = False) # Copied dataframedisplay(new_data_2) # checking whether dataframe is modified or not# Original dataframedisplay(dataframe) # Putting Inplace=Truedataframe.rename(columns = {'Name':'FirstName'},                 inplace = True) # checking whether dataframe is modified or not# Original dataframedisplay(dataframe)
Output : 
sumitgumber28
pushpakveer19
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Python | os.path.join() method
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python | Get unique values from a list
Python | datetime.timedelta() function