text_html_output_1.png
import matplotlib.pyplot as plt

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

import seaborn as sns

train_df = pd.read_csv('/kaggle/input/titanic/train.csv')
train_df.head().T

test_df = pd.read_csv('/kaggle/input/titanic/test.csv')
test_df.head().T

train_df.head().T

train_df = train_df.drop(['PassengerId', 'Name', 'Ticket'], axis=1)
test_df = test_df.drop(['Name', 'Ticket'], axis=1)

train_df.isnull().sum()

test_df.isnull().sum()

train_df['Embarked'].fillna(train_df['Embarked'].mode()[0], inplace=True)
train_df.isnull().sum()
fig, (axis1, axis2, axis3) = plt.subplots(1, 3, figsize=(15, 5))
sns.countplot(x='Embarked', data=train_df, ax=axis1)
sns.countplot(x='Survived', hue='Embarked', data=train_df, order=[1, 0], ax=axis2)
combined = train_df[['Embarked', 'Survived']].groupby(['Embarked'], as_index=False).mean()
sns.barplot(x='Embarked', y='Survived', data=combined, order=['S', 'C', 'Q'], ax=axis3)
train_df1 = pd.get_dummies(train_df, prefix='Embark', columns=['Embarked'])
test_df1 = pd.get_dummies(test_df, prefix='Embark', columns=['Embarked'])
train_df1.head().T