text_html_output_1.png
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

train_file_path = '../input/titanic/train.csv'
gs_file_path = '../input/titanic/gender_submission.csv'
main_df = pd.read_csv(train_file_path)
gender_sub_df = pd.read_csv(gs_file_path)

cols1 = main_df.columns.to_list()
cols2 = gender_sub_df.columns.to_list()

main_df.drop(main_df[main_df['Embarked'].isnull()].index, inplace=True, axis=0)

main_df_sex1 = main_df[['Survived', 'Sex']]
main_df_sex1 = main_df_sex1.value_counts().to_frame()
main_df_sex1.reset_index(drop=False, inplace=True)
main_df_sex1.rename(columns={0: 'Counts'}, inplace=True)
main_df_sex1['Survived'] = main_df_sex1['Survived'].replace([0, 1], ['Not-Survived', 'Survived'])
main_df_sex1.set_index(['Survived', 'Sex'], drop=True, inplace=True)
main_df_sex1

main_df_sex1.reset_index(drop=False, inplace=True)
for i in main_df_sex1.index:
    if main_df_sex1.iloc[i]['Sex'] == 'male':
        main_df_sex1.loc[i, '%'] = main_df_sex1.iloc[i]['Counts'] / 577 * 100
    if main_df_sex1.iloc[i]['Sex'] == 'female':
        main_df_sex1.loc[i, '%'] = main_df_sex1.iloc[i]['Counts'] / 312 * 100
main_df_sex1

male_stats = main_df_sex1[main_df_sex1['Sex'] == 'male']
male_stats.drop(['Counts'], axis=1, inplace=True)
male_stats.set_index(['Survived', 'Sex'], drop=True, inplace=True)
female_stats = main_df_sex1[main_df_sex1['Sex'] == 'female']
female_stats.drop(['Counts'], axis=1, inplace=True)
female_stats.set_index(['Survived', 'Sex'], drop=True, inplace=True)

female_stats