I want to update the Nan values in Age column based on class of the person.The csv file contain Age and class of person.
If the person is of 1st class his age is 35.
If the person is of 2nd class his age is 30.
If the person is of 3rd class his age is 25.
Csv File
Age Class
32 2
26 3
Nan 1
36 1
24 3
Nan 2
Nan 3
Update Csv File
Age Class
32 2
26 3
35 1
36 1
24 3
30 2
25 3
I have tried some pandas function but it did not worked.
df[ (df.Age.isnull()) & (df.Pclass==1) ]['Age'] = 35
df[ (df.Age.isnull()) & (df.Pclass==2) ]['Age'] = 30
df[ (df.Age.isnull()) & (df.Pclass==3) ]['Age'] = 25
Please provide a solution....