application_vnd.jupyter.stderr_output_1.png
from collections import Counter

import numpy as np

import pandas as pd

markdown_data = pd.read_csv('../input/titanic/train.csv')
final_approval_data = pd.read_csv('../input/titanic/test.csv')
passenger_id_final = final_approval_data['PassengerId']

def detect_outliers(df, n, features):
    """
    Takes a dataframe df of features and returns a list of the indices
    corresponding to the observations containing more than n outliers according
    to the Tukey method.
    """
    outlier_indices = []
    for col in features:
        Q1 = np.percentile(df[col], 25)
        Q3 = np.percentile(df[col], 75)
        IQR = Q3 - Q1
        outlier_step = 1.5 * IQR
        outlier_list_col = df[(df[col] < Q1 - outlier_step) | (df[col] > Q3 + outlier_step)].index
        outlier_indices.extend(outlier_list_col)
    outlier_indices = Counter(outlier_indices)
    multiple_outliers = list((k for k, v in outlier_indices.items() if v > n))
    return multiple_outliers
Outliers_to_drop = detect_outliers(markdown_data, 2, ['Age', 'SibSp', 'Parch', 'Fare'])
markdown_data.loc[Outliers_to_drop]

markdown_data = markdown_data.drop(Outliers_to_drop).reset_index(drop=True)

train_len = len(markdown_data)
data = pd.concat([markdown_data, final_approval_data], axis=0).reset_index(drop=True)
data.isnull().sum()