text_plain_output_1.png
import pandas as pd # data processing

train_data = pd.read_csv('/kaggle/input/titanic/train.csv')
test_data = pd.read_csv('/kaggle/input/titanic/test.csv')

train_data.isna().sum()

train_data = train_data.drop(labels=['Cabin'], axis='columns')
test_data = test_data.drop(labels=['Cabin'], axis='columns')

train_data.shape

train_data.isna().sum()

test_data.isna().sum()

train_data.sample(10)

Ticket1 = []
TicketNumber1 = []
TicketNumber2 = []
for i in list(train_data.Ticket):
    if not i.isdigit():
        Ticket1.append(i.replace('.', '').replace('/', '').strip().split(' ')[0])
    else:
        Ticket1.append('X')
        TicketNumber1.append(0)
train_data['Ticket'] = Ticket1
Ticket2 = []
for j in list(test_data.Ticket):
    if not j.isdigit():
        Ticket2.append(j.replace('.', '').replace('/', '').strip().split(' ')[0])
    else:
        Ticket2.append('X')
test_data['Ticket'] = Ticket2

unique1 = []
unique2 = []
for i in train_data['Ticket'].unique():
    if i not in test_data['Ticket'].unique():
        unique1.append(i)
    else:
        pass
for j in test_data['Ticket'].unique():
    if j not in train_data['Ticket'].unique():
        unique2.append(j)
    else:
        pass

unique1 = ['Ticket_' + s for s in unique1]
unique2 = ['Ticket_' + s for s in unique2]

train_data = pd.get_dummies(train_data, columns=['Ticket'])
test_data = pd.get_dummies(test_data, columns=['Ticket'])

train_data = train_data.drop(labels=unique1, axis='columns')
test_data = test_data.drop(labels=unique2, axis='columns')

train_data = train_data.drop(labels='Name', axis='columns')
test_data = test_data.drop(labels='Name', axis='columns')

train_data = train_data.drop(labels='Survived', axis=1)

train_data.columns