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

df = pd.read_csv('../input/titanic/train.csv')

df.shape

df.isnull().sum() * 100 / df.shape[0]

df1 = df.copy()

df1.drop('Cabin', axis=1, inplace=True)

df1.Embarked.isnull().sum()

df1 = df1.dropna(axis=0, subset=['Embarked'])

df1.shape

df1_pc1 = df1[df1['Pclass'] == 1]

df1_pc1.shape

df1_pc1_male = df1_pc1[df1_pc1['Sex'] == 'male']

df1_pc1_female = df1_pc1[df1_pc1['Sex'] == 'female']

df1_pc1 = df1_pc1_male.append(df1_pc1_female)

df1_pc1.shape

df1_pc2 = df1[df1['Pclass'] == 2]
df1_pc2.shape

df1_pc2_male = df1_pc2[df1_pc2['Sex'] == 'male']
df1_pc2_male['Age'].fillna(value=df1_pc2_male['Age'].mean(), inplace=True)

df1_pc2_female = df1_pc2[df1_pc2['Sex'] == 'female']
df1_pc2_female['Age'].fillna(value=df1_pc2_female['Age'].mean(), inplace=True)

df1_pc2 = df1_pc2_male.append(df1_pc2_female)
df1_pc2.shape

df1_pc3 = df1[df1['Pclass'] == 3]
df1_pc3.shape

df1_pc3_male = df1_pc3[df1_pc3['Sex'] == 'male']
df1_pc3_male['Age'].fillna(value=df1_pc3_male['Age'].mean(), inplace=True)

df1_pc3_female = df1_pc3[df1_pc3['Sex'] == 'female']
df1_pc3_female['Age'].fillna(value=df1_pc3_female['Age'].mean(), inplace=True)

df1_pc3 = df1_pc3_male.append(df1_pc3_female)

df1_pc3.shape

df1_pc1 = df1_pc1.append(df1_pc2)
df1 = df1_pc1.append(df1_pc3)

df1.shape