text_plain_output_1.png
from datetime import datetime

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

name = 'Raghu'
from datetime import datetime
started_at = datetime.now().strftime('%H:%M:%S')
train_data = pd.read_csv('/kaggle/input/titanic/train.csv')
test_data = pd.read_csv('/kaggle/input/titanic/test.csv')

def massage_data(data):
    data['Honorific'] = data['Name']
    titles = data['Name'].str.split(',')
    for indx, title in enumerate(titles):
        data['Honorific'][indx] = title[1].split('.')[0]
    data['HonorificEnc'] = data['Honorific']
    for indx, hon in enumerate(train_data.Honorific.value_counts().index):
        data.HonorificEnc.replace(hon, indx, inplace=True)
    data['CoPassengers'] = data['SibSp'] + data['Parch']
    data.Sex.replace('male', 0, inplace=True)
    data.Sex.replace('female', 1, inplace=True)
    most_likely_fare = data['Fare'].mean()
    data['Fare'] = data['Fare'].fillna(most_likely_fare)
    most_likely_age = data['Age'].mean()
    data['Age'] = data['Age'].fillna(most_likely_age)
    most_likely_embarkation = data['Embarked'].mode()
    data['Embarked'] = data['Embarked'].fillna(most_likely_embarkation)
    data['EmbarkedEnc'] = data['Embarked']
    data.EmbarkedEnc.replace('S', 0, inplace=True)
    data.EmbarkedEnc.replace('C', 1, inplace=True)
    data.EmbarkedEnc.replace('Q', 2, inplace=True)
    return data

test_data = massage_data(test_data)
train_data = massage_data(train_data)

columns_for_fitting = ['Sex', 'CoPassengers', 'Pclass', 'Fare', 'Age', 'EmbarkedEnc']
data = [train_data, test_data]
for c in columns_for_fitting:
    print(c)
    for d in data:
        print(d[c].value_counts())
    print('-----')