To replace the Nan(missing values) by using forward and backward methods using python.
Import pandas library.
Read the sample data set.
Find the missing values in the data set.
Replace the missing values by using pad() and bfill().
#import libraries
import pandas as pd
#Read the sample data
data=pd.read_csv(‘/home/soft27/soft27
/Sathish/Pythonfiles/Houseprice.csv’)
#create data frame
df=pd.DataFrame(data)
print(“Actual data frame is:\n”,df)
#Find the missing values
print(“Find missing values”)
print(df.isnull())
#Replace the missing values(Nan) using forward
print(“Replace the Nan values”)
print(df.fillna(method=’pad’))
#Replace the missing values(Nan) using backward
print(df.fillna(method=’bfill’))