impute mode pandas code example
Example 1: impute mode pandas
cols = ["workclass", "native-country"]
df[cols]=df[cols].fillna(df.mode().iloc[0])
Example 2: mode imputation in python
df['country'].fillna(df['country'].mode()[0], inplace = True)
cols = ["workclass", "native-country"]
df[cols]=df[cols].fillna(df.mode().iloc[0])
df['country'].fillna(df['country'].mode()[0], inplace = True)