Skip to content

Instantly share code, notes, and snippets.

@finlytics-hub
Created July 5, 2020 13:18
Show Gist options
  • Save finlytics-hub/f6a1c47e802385b1d875b9ba58f6826b to your computer and use it in GitHub Desktop.
Save finlytics-hub/f6a1c47e802385b1d875b9ba58f6826b to your computer and use it in GitHub Desktop.
Practical demonstration of using IQR to drop outlier rows
# Calculate 1st and 3rd percentiles, and IQR
Q1 = X_train.quantile(0.25)
Q3 = X_train.quantile(0.75)
IQR = Q3 - Q1
# Filter out the rows that fall outside the 1.5 threshold in each column
X_train_new = X_train[~((X_train < (Q1 - 1.5 * IQR)) | (X_train > (Q3 + 1.5 * IQR))).any(axis=1)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment