application_vnd.jupyter.stderr_output_1.png
from collections import Counter

import numpy as np

import pandas as pd

test_df = pd.read_csv('/kaggle/input/titanic/test.csv')
train_df = pd.read_csv('/kaggle/input/titanic/train.csv')
test_passengerId = test_df['PassengerId']

def detectOutliers(df, features):
    outlier_indices = []
    for i in features:
        Q1 = np.percentile(df[i], 25)
        Q3 = np.percentile(df[i], 75)
        IQR = Q3 - Q1
        outlierStep = IQR * 1.5
        outlier_listCol = df[(df[i] < Q1 - outlierStep) | (df[i] > Q3 + outlierStep)].index
        outlier_indices.extend(outlier_listCol)
    outlier_indices = Counter(outlier_indices)
    multiple_outliers = list((i for i, k in outlier_indices.items() if k > 2))
    return multiple_outliers

train_df.loc[detectOutliers(train_df, ['Age', 'SibSp', 'Parch', 'Fare'])]
train_df = train_df.drop(detectOutliers(train_df, ['Age', 'SibSp', 'Parch', 'Fare']), axis=0).reset_index(drop=True)
train_df

train_df_len = len(train_df)
train_df = pd.concat([train_df, test_df], axis=0).reset_index(drop=True)

train_df.columns[train_df.isnull().any()]