text_plain_output_1.png image_output_1.png
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_df = pd.read_csv('../input/train.csv', dtype={'Age': np.float64})
test_df = pd.read_csv('../input/test.csv', dtype={'Age': np.float64})

"""
Takeaways
Age is null for some rows
Cabin is almost always null
Embarked is null for only 2 rows
"""

"""
Takeaways
Fare is null for one row
Cabin null for most
Age null for some
"""

letters = 'ABCDEFGHIJKLM'
train_df['CabinStartsWith'] = float(-1)
train_df['CabinStartsWithLetter'] = ''
train_df['CabinStartsWithLetter'][train_df['Cabin'] != 'Missing'] = train_df['Cabin'].str[0]
train_df['CabinStartsWith'][train_df['CabinStartsWithLetter'] == 'A'] = 0
train_df['CabinStartsWith'][train_df['CabinStartsWithLetter'] == 'B'] = 1
train_df['CabinStartsWith'][train_df['CabinStartsWithLetter'] == 'C'] = 2
train_df['CabinStartsWith'][train_df['CabinStartsWithLetter'] == 'D'] = 3
train_df['CabinStartsWith'][train_df['CabinStartsWithLetter'] == 'E'] = 4
train_df['CabinStartsWith'][train_df['CabinStartsWithLetter'] == 'F'] = 5
train_df['CabinStartsWith'][train_df['CabinStartsWithLetter'] == 'G'] = 6
test_df['CabinStartsWith'] = -1
test_df['CabinStartsWithLetter'] = ''
test_df['CabinStartsWithLetter'][test_df['Cabin'] != 'Missing'] = test_df['Cabin'].str[0]
test_df['CabinStartsWith'][test_df['CabinStartsWithLetter'] == 'A'] = 0
test_df['CabinStartsWith'][test_df['CabinStartsWithLetter'] == 'B'] = 1
test_df['CabinStartsWith'][test_df['CabinStartsWithLetter'] == 'C'] = 2
test_df['CabinStartsWith'][test_df['CabinStartsWithLetter'] == 'D'] = 3
test_df['CabinStartsWith'][test_df['CabinStartsWithLetter'] == 'E'] = 4
test_df['CabinStartsWith'][test_df['CabinStartsWithLetter'] == 'F'] = 5
test_df['CabinStartsWith'][test_df['CabinStartsWithLetter'] == 'G'] = 6