text_html_output_1.png
import numpy as np

import pandas as pd

import pandas as pd
t = pd.read_csv('../input/titanic/train.csv')
t

pd.pivot_table(t, index='SibSp', columns='Parch', values='Survived', aggfunc='count', margins=True)

pd.pivot_table(t, index='SibSp', values='Survived', aggfunc='count', margins=True)

pd.pivot_table(t, index='SibSp', columns='Survived', values='PassengerId', aggfunc='count', margins=True)

t['Title'] = t.Name.str.extract(' ([A-Za-z]+)\\.', expand=False)
pd.crosstab(t['Title'], t['Sex'])

t = t.drop(['Name', 'PassengerId', 'Ticket', 'Cabin'], axis=1)

import numpy as np
guess_ages = np.zeros((2, 3))
guess_ages

for i in range(0, 2):
    for j in range(0, 3):
        guess_df = t[(t['Sex'] == i) & (t['Pclass'] == j + 1)]['Age'].dropna()
        age_guess = guess_df.median()
        guess_ages[i, j] = int(age_guess / 0.5 + 0.5) * 0.5
for i in range(0, 2):
    for j in range(0, 3):
        t.loc[t.Age.isnull() & (t.Sex == i) & (t.Pclass == j + 1), 'Age'] = guess_ages[i, j]
t['Age'] = t['Age'].astype(int)

t = t.drop(['Age'], axis=1)

t.loc[t['Familysize'] == 1, 'Isalone'] = 1

t = t.drop(columns=['SibSp', 'Parch', 'Familysize'])

ME = t.Embarked.dropna().mode()[0]

t.head()