<jupyter_start><jupyter_text>Step 2<jupyter_code>sns.countplot(x='Survived', data=train)<jupyter_output><empty_output><jupyter_text>Step 3<jupyter_code>first_surv = train.loc[(train['Survived']==1) & (train['Pclass'] == 1)]
first = train.loc[(train['Pclass'] == 1)]
first_surv_frac = first_surv['Survived'].count() / first['Pclass'].count()
first_surv_frac
sns.countplot(x='Survived', data=train,hue='Pclass')<jupyter_output><empty_output><jupyter_text>Step 4<jupyter_code>sns.countplot(x='Sex',data=train,hue='Pclass')<jupyter_output><empty_output><jupyter_text>Step 5<jupyter_code>sns.histplot(train, x='Age',kde=False, hue='Survived', element='poly')<jupyter_output><empty_output><jupyter_text>Step 6<jupyter_code>print("The average age of the survived passangers is :", round((train[train["Survived"]==1]['Age'].mean()),2) )
print("The average age of the dead passangers is :", round((train[train["Survived"]==0]['Age'].mean()),2) )<jupyter_output>The average age of the survived passangers is : 28.34
The average age of the dead passangers is : 30.63<jupyter_text>Step 7<jupyter_code>train.groupby('Pclass')['Age'].mean()<jupyter_output><empty_output><jupyter_text>Judging from the box plot above, it looks like the average age of 1st class passengers is 37, of the 2nd class 29 and of the 3rd 24.<jupyter_code>def fillna_age(cols):
    p_age = cols[0]
    p_class = cols[1]
    
    if pd.isnull(p_age):
        
        if p_class == 1:
            return 38
        elif p_class == 2:
            return 30
        else:
            return 25
    else:
        return p_age
train['Age'] = train[['Age','Pclass']].apply(fillna_age,axis=1)
sns.heatmap(train.isnull(),yticklabels=False,cbar=False,cmap='viridis')
train.drop('Cabin',axis=1,inplace=True)
train.dropna(inplace=True)
sns.heatmap(train.isnull(),yticklabels=False,cbar=False,cmap='viridis')<jupyter_output><empty_output><jupyter_text>Step 8<jupyter_code>train.groupby(['Sex', 'Pclass'])['Survived'].count().plot.bar()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16641828117237953, 'fraction_numerical': 0.02136115250869349, 'mean_word_length': 6.776061776061776, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '67280', 'license': 'MIT', 'n_tokens_mistral': 811, 'n_tokens_neox': 762, 'n_words': 116, 'path': 'week2/Sec_2.1.4_ML_Methods.ipynb', 'repo_name': 'boraatlay/bootcamp', 'size': '2013'}