Skip to content

Instantly share code, notes, and snippets.

@mmmayo13
Created March 21, 2018 22:57
Show Gist options
  • Save mmmayo13/5107537b5be3c30108a59f2ed9125c4d to your computer and use it in GitHub Desktop.
Save mmmayo13/5107537b5be3c30108a59f2ed9125c4d to your computer and use it in GitHub Desktop.
def get_age(df):
for pclass in [1,2,3]:
for sex in ['male','female']:
for title in ['Miss','Mr','Master','Mrs','Unknown']:
ds = df[df['Pclass'] == pclass]
ds = ds[ds['Sex'] == sex]
ds = ds[ds['Title'] == title]
median = ds['Age'].median()
df.loc[(df['Age'].isnull()) & (df['Pclass'] == pclass) & (df['Sex'] == sex), 'Age'] = median
get_age(titanic_full)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment