I have a dataset that has a number of numeric variables and a number of ordinal nominal variables. To fill in the missing value I want to use the mode for nominal variables. The following code does not fill some of the nominal value. Please advise why the code is wrong.
df = pd.read_csv(sample.csv')
nominal_data = df.select_dtypes(include=[np.object])
nominalColumns= list(set(nominal_data.columns))
df[nominalColumns]=df[nominalColumns].fillna(df[nominalColumns].mode())
age | class
------------
1 | no
2 | yes
3 | NAN
4 | yes
5 | no
6 | NAN
7 | no
8 | yes
9 | no
10 | NAN