image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import numpy as np # linear algebra

import pandas as pd

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

train = pd.read_csv('/kaggle/input/titanic/train.csv')
test = pd.read_csv('/kaggle/input/titanic/test.csv')
submit = pd.DataFrame(test['PassengerId'])

train['title'] = 0
for i in range(0, len(train)):
    train.loc[i, 'title'] = train['Name'].iloc[i].split(',')[1].split('.')[0][1:]
train['title'].replace({'Mr': 1, 'Miss': 2, 'Mrs': 2, 'Master': 3, 'Dr': 4, 'Rev': 5}, inplace=True)
train['title'].replace(['Major', 'Mlle', 'Col', 'Don', 'the Countess', 'Sir', 'Capt', 'Mme', 'Lady', 'Jonkheer', 'Ms'], 6, inplace=True)

for i in range(len(train)):
    if not pd.isnull(train['Cabin'].iloc[i]):
        train.loc[i, 'Cabin'] = train['Cabin'].loc[i][0]
train['Cabin'].replace({'C': 1, 'B': 2, 'D': 3, 'E': 4, 'A': 5, 'F': 6, 'G': 7, 'T': 8}, inplace=True)
train['Fare'] = np.sqrt(train['Fare'])

train.drop(['Name', 'SibSp', 'Parch', 'Ticket', 'PassengerId', 'Cabin'], axis=1, inplace=True)

train.hist(figsize=(15, 10))
plt.show()