Fill in missing values with the mean

        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

Guess you like

Origin blog.csdn.net/qq_43657442/article/details/109125353