application_vnd.jupyter.stderr_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

train = pd.read_csv('...train.csv')
test = pd.read_csv('...test.csv')

train = train.drop(train[['Cabin', 'Embarked', 'Name', 'Ticket']], axis=1)
test = test.drop(test[['Cabin', 'Embarked', 'Name', 'Ticket']], axis=1)
train.dropna(axis=0, how='any', inplace=True)

corr = train.corr()

train.drop(train[['Fare', 'SibSp', 'Parch']], axis=1, inplace=True)
test.drop(test[['Fare', 'SibSp', 'Parch']], axis=1, inplace=True)

sex_variable = train.pivot_table(index='Sex', values='Survived')

survived = train[train['Survived'] == 1]
died = train[train['Survived'] == 0]

def category_age(df, cut_points, label_names):
    df['Age'] = df['Age'].fillna(-0.5)
    df['Age_categories'] = pd.cut(df['Age'], cut_points, labels=label_names)
    return df
cut_points = [0, 5, 12, 18, 35, 60, 100]
label_names = ['Infant', 'Child', 'Teenager', 'Young Adult', 'Adult', 'Senior']
train = category_age(train, cut_points, label_names)
test = category_age(test, cut_points, label_names)
pivot = train.pivot_table(index='Age_categories', values='Survived')
pivot.plot.bar()
plt.show()