Working with census data, I want to replace NaNs in two columns ("workclass" and "native-country") with the respective modes of those two columns. I can get the modes easily:
mode = df.filter(["workclass", "native-country"]).mode()
which returns a dataframe:
workclass native-country
0 Private United-States
However,
df.filter(["workclass", "native-country"]).fillna(mode)
does not replace the NaNs in each column with anything, let alone the mode corresponding to that column. Is there a smooth way to do this?