0

In the Titanic data set passengers, sex and age are given, but there are some empty values for age. I would like to enter the average by sex.

    Sex
    female    27.915709
    male      30.726645

Where the sex is equal to male I would like to ent the average male age and the same for sex equal to female

I'm somewhat new haven't tried too much

titanic.Sex = 'male' and titanic.Age.fillna(mean_homme)

The Nan for male age will equal the average male age

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

1 Answers1

1

Try something like this,

df['male']=df['male'].fillna(df['male'].mean())
Arun Augustine
  • 1,690
  • 1
  • 13
  • 20