text_html_output_1.png
from collections import Counter

import numpy as np  # linear algebra

import pandas as pd  # read and wrangle dataframes

df = pd.read_csv('../input/glass/glass.csv')
features = df.columns[:-1].tolist()

df.dtypes

def outlier_hunt(df):
    """
    Takes a dataframe df of features and returns a list of the indices
    corresponding to the observations containing more than 2 outliers. 
    """
    outlier_indices = []
    for col in df.columns.tolist():
        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 > 2))
    return multiple_outliers
print('The dataset contains %d observations with more than 2 outliers' % len(outlier_hunt(df[features])))