Suppose the data has been read in through the following code
import pandas as pd
titanic_data = pd.read_csv('titanic_data.csv',encoding = 'gbk')
Mean fill
for column in list(titanic_data.columns[titanic_data.isnull().sum() > 0]):
mean_val = titanic_data[column].mean()
titanic_data[column].fillna(mean_val, inplace=True)
pandas (sum, mean, max, min, idxmax, idxmin, cumsum, mad, std, var, diff, pct_change, corr) these functions will exclude NaN values
by default. By specifying skipna=False
, you can includeNan