Created
March 21, 2018 22:57
-
-
Save mmmayo13/5107537b5be3c30108a59f2ed9125c4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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