text_plain_output_1.png
import pandas as pd

import pandas as pd
import numpy as np
import re
from sklearn.preprocessing import LabelEncoder
from sklearn.ensemble import RandomForestClassifier
from sklearn import metrics
from sklearn.model_selection import cross_val_score
train = pd.read_csv('/kaggle/input/titanic/train.csv')
test = pd.read_csv('/kaggle/input/titanic/test.csv')
example = pd.read_csv('/kaggle/input/titanic/gender_submission.csv')
train.columns = train.columns.str.lower()
test.columns = test.columns.str.lower()

general = pd.concat([train, test], axis=0)
general['fare'] = general.groupby('pclass')['fare'].transform(lambda x: x.fillna(x.median()))
general['embarked'] = general.groupby(['pclass'])['embarked'].transform(lambda x: x.fillna(x.value_counts().idxmax()))
general['age'] = general.groupby(['pclass', 'parch', 'sibsp'])['age'].transform(lambda x: x.fillna(x.median()))
general['age'] = general.groupby(['pclass'])['age'].transform(lambda x: x.fillna(x.median()))
general.info()