1In [7]: df
2Out[7]:
3 0 1
40 NaN NaN
51 -0.494375 0.570994
62 NaN NaN
73 1.876360 -0.229738
84 NaN NaN
9
10In [8]: df.fillna(0)
11Out[8]:
12 0 1
130 0.000000 0.000000
141 -0.494375 0.570994
152 0.000000 0.000000
163 1.876360 -0.229738
174 0.000000 0.000000
1def exercise4(df):
2 df1 = df.select_dtypes(np.number)
3 df2 = df.select_dtypes(exclude = 'float')
4 mode = df2.mode()
5 df3 = df1.fillna(df.mean())
6 df4 = df2.fillna(mode.iloc[0,:])
7 new_df = [df3,df4]
8 df5 = pd.concat(new_df,axis=1)
9 new_cols = list(df.columns)
10 df6 = df5[new_cols]
11 return df6