text_html_output_1.png
import pandas as pd

import pandas as pd
import numpy as np
train = pd.read_csv('../input/titanic/train.csv')
test = pd.read_csv('../input/titanic/test.csv')
gender_submission_df = pd.read_csv('../input/titanic/gender_submission.csv')

def groupby_mean_sort(df, col):
    return df[[col, 'Survived']].groupby([col], as_index=False).mean().sort_values(by='Survived', ascending=False)
list_for_groupby_mean_sort = ['Pclass', 'Age', 'SibSp', 'Parch', 'Sex', 'Cabin', 'Embarked']
groupby_mean_sort(train, 'SibSp')

Parch_and_SibSp_col = train.Parch.astype(str) + ':' + train.SibSp.astype(str)
train.assign(Parch_SibSp=Parch_and_SibSp_col)[['Parch_SibSp', 'Survived']].groupby(['Parch_SibSp'], as_index=False).mean().sort_values(by='Survived', ascending=False)

Parch_and_SibSp_col = train.Parch.astype(str) + ':' + train.SibSp.astype(str)
train.assign(Parch_SibSp=Parch_and_SibSp_col)[['Parch_SibSp', 'Survived', 'Pclass', 'Age']].groupby(['Parch_SibSp'], as_index=False).median().sort_values(by='Survived', ascending=False)

train.assign(Sex_Pclass=train.Sex.astype(str) + ':' + train.Pclass.astype(str))[['Sex_Pclass', 'Survived', 'Pclass', 'Age']].groupby(['Sex_Pclass'], as_index=False).mean(numeric_only=True).sort_values(by='Survived', ascending=False)

train.assign(Embarked_Sex_Pclass=train.Embarked + ':' + train.Sex + ':' + train.Pclass.astype(str))[['Embarked_Sex_Pclass', 'Survived', 'Age']].groupby(['Embarked_Sex_Pclass'], as_index=False).mean(numeric_only=True).sort_values(by='Survived', ascending=False)

groupby_mean_sort(train, 'Age')