Created
April 12, 2022 10:46
-
-
Save AayushSameerShah/1fab7bb2a6652810514d850a6b094cfb to your computer and use it in GitHub Desktop.
Simply pass the column names of which you want to find the outliers from. YOU NEED TO HAVE THE DATAFRAME NAMED "DF".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_outlier_indices(columns_list): | |
indices = [] | |
for column in columns_list: | |
feature = df[column] | |
Q1, Q3 = feature.quantile([0.25, 0.75]).values | |
IQR = Q3 - Q1 | |
lower = Q1 - (1.5 * IQR) | |
upper = Q3 + (1.5 * IQR) | |
inds = list(df[(df[column] < lower) | (df[column] > upper)].index.values) | |
indices.extend(inds) | |
return set(indices) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment