Inplace function

what does inplace function do?

 

The inplace=True parameter replaces the existing dataframe

The inplace=False (default) parameter keeps the existing dataframe as it is and returns an updated dataframe



Example:

import pandas as pd

from datetime import datetime as dt

df = pd.DataFrame(data=[22,75,3],                  

                  columns=['A'])

Existing dataframe df will be as it is

df_new will hold the sorted values

df_new = df.sort_values(by='A')

print("df values")

print(df)

print("df_new values")

print(df_new)

The sorted values will be overwritten in existing dataframe df

df.sort_values(by='A', inplace=True)

print("df values after inplace=True")

print(df)