Skip to content

Instantly share code, notes, and snippets.

@AayushSameerShah
Created April 12, 2022 10:46
Show Gist options
  • Save AayushSameerShah/1fab7bb2a6652810514d850a6b094cfb to your computer and use it in GitHub Desktop.
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".
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