fill na with mode and mean python

Solutions on MaxInterview for fill na with mode and mean python by the best coders in the world

showing results for - "fill na with mode and mean python"
Soline
07 May 2020
1cateogry_columns=df.select_dtypes(include=['object']).columns.tolist()
2integer_columns=df.select_dtypes(include=['int64','float64']).columns.tolist()
3
4for column in df:
5    if df[column].isnull().any():
6        if(column in cateogry_columns):
7            df[column]=df[column].fillna(df[column].mode()[0])
8        else:
9            df[column]=df[column].fillna(df[column].mean)