image_output_1.png
import matplotlib.pyplot as plt

import os

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

import seaborn as sns

import numpy as np
import pandas as pd
import seaborn as sns
sns.set(rc={'figure.figsize': (30, 18)})
import matplotlib.pyplot as plt
import os

train = pd.read_csv('../input/titanic/train.csv')
test = pd.read_csv('../input/titanic/test.csv')
all_data = [train, test]
submition_id = test['PassengerId']

def check_missing(data, dtype='object'):
    if dtype == 'object':
        nulls = data.select_dtypes(include='object')
    else:
        nulls = data.select_dtypes(exclude='object')
    nulls = nulls.isnull().sum()
    nulls = nulls.drop(nulls[nulls == 0].index).sort_values(ascending=False)
    return pd.DataFrame(nulls)
    '\n    this function detecting the missing values by the type\n    and return data frame contains two columns \n    feature name : how many NAN\n    ----------\n    parameters\n    ----------\n    data : which data frame you need to check it\n    \n    dtype : do you looking for numerical featuers or categorical ? \n    \n    '

def lower_case_features(data):
    data.columns = [col.lower() for col in list(data)]
    '\n    simple function to return evry single column name in lowercase\n    list(data) ==> contains every column title in the data frame \n    \n    '
lower_case_features(train)
lower_case_features(test)

for dataset in [train, test]:
    dataset['agecat'] = pd.cut(dataset['age'], bins=5, labels=['0-16', '16-32', '32-48', '48-64', '64-85'], include_lowest=True)
pd.DataFrame(train[['agecat', 'survived']].value_counts())

fig = sns.catplot(
    data = train, x = 'agecat', y = 'survived', kind = 'bar',
    palette = 'deep'
)
fig.set_axis_labels('Ages', 'survival rate', size = 15)
fig.fig.suptitle('survival rate per ages', verticalalignment = 'center', size = 15)
plt.show();

fig = sns.catplot(
    data = train, x = 'sex', y = 'survived', kind = 'bar',
    palette = 'deep'
)
fig.set_axis_labels('Sex', 'Survival rate', size = 15)
fig.fig.suptitle('survival rate per gender', verticalalignment = 'center', size = 15)
plt.show();

pd.DataFrame(train.embarked.value_counts())

fig = sns.catplot(data=train, x='embarked', y='survived', kind='bar', palette='deep')
fig.set_axis_labels('embarked', 'survival rate', size=15)
fig.fig.suptitle('survival rate per Port of Embarkation', verticalalignment='bottom', size=14)
plt.show()