I have a DataFrame which has columns name age,salary. There are some NaN values too. I want to fill those values using Mean and Median.
Original DataFrame
age salary
0 20.0 NaN
1 45.0 22323.0
2 NaN 598454.0
3 32.0 NaN
4 NaN 48454.0
Fill missing age with the mean() and salary with median() of their respective columns using apply().
I used
df['age','salary'].apply({'age':lambda row:row.fillna(row.mean()), 'salary':lambda row:row.fillna(row.median()) })
It is showing Key error 'age','salary' even after I use axis=1
Ecpected Output
age salary
0 20.000000 48454.0
1 45.000000 22323.0
2 32.333333 598454.0
3 32.000000 48454.0
4 32.333333 48454.0
Can someone show me how to do it properly and what is happening in the background?
Please tell if there are other ways too. I am learning Pandas from scratch