seeing my problem tried to replicate it in a simple example to avoid sharing my data.
A sample pd DF:
df_sample = pd.DataFrame([[1, 2], [3, 4], [5, 6], [float('nan'), 8]], columns=["A", "B"])
Tried calculating mean for all columns using:
df_sample.mean()
Works well but
df_sample.mode()
doesn't work like mean as seen in output below:
Any ideas why and how can I get mode of all columns using something similar to df.mode()?Btw my purpose is to impute missing data in multiple variables with mode and it didn't replace NaNs with mode in my original data.
df_sample['A'].fillna(df_sample['A'].mode())
But now I realize, seems like mode itself has a problem in definition. Any ideas? Thanks in advance!