text_plain_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_data = pd.read_csv('/kaggle/input/titanic/train.csv')

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

train_data.dtypes

train_data.isnull().sum()

test_data.isnull().sum()

train_data.fillna(train_data.Age.mean(), inplace=True)
train_data['Cabin'].fillna('Unknown', inplace=True)
train_data['Embarked'].fillna('Unknown', inplace=True)
test_data.fillna(test_data['Age'].mean(), inplace=True)
test_data.fillna(test_data['Fare'].mean(), inplace=True)
test_data['Cabin'].fillna('Unknown', inplace=True)

train_data.groupby(['Sex'])['Survived'].value_counts(normalize=True)

train_data.groupby(['Pclass'])['Survived'].value_counts(normalize=True)

sns.barplot(x='Pclass', y='Survived', data=train_data)
plt.xlabel('Passenger Class')
plt.ylabel('Survival Rate')
plt.title('Survival Rates by Passenger Class on the Titanic')
plt.show()