-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutliers.py
31 lines (26 loc) · 1.49 KB
/
outliers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import pandas as pd
def showoutliers(df, column_name = ""):
iqr = df[column_name].quantile(.75) - df[column_name].quantile(.25)
lowerbound = (df[column_name].quantile(.25)) - iqr * 1.5
upperbound = (df[column_name].quantile(.75)) + iqr * 1.5
lowerbound_outliers = df[df[column_name] < lowerbound]
higherbound_outliers = df[df[column_name] > upperbound]
outliers = pd.concat([lowerbound_outliers,higherbound_outliers])
return outliers
def countoutliers(df, column_name = ""):
iqr = df[column_name].quantile(.75) - df[column_name].quantile(.25)
lowerbound = (df[column_name].quantile(.25)) - iqr * 1.5
upperbound = (df[column_name].quantile(.75)) + iqr * 1.5
lowerbound_outliers = df[df[column_name] < lowerbound]
higherbound_outliers = df[df[column_name] > upperbound]
outliers = pd.concat([lowerbound_outliers,higherbound_outliers])
return len(outliers)
def removeoutliers(df, column_name = ""):
iqr = df[column_name].quantile(.75) - df[column_name].quantile(.25)
lowerbound = (df[column_name].quantile(.25)) - iqr * 1.5
upperbound = (df[column_name].quantile(.75)) + iqr * 1.5
lowerbound_outliers = df[df[column_name] < lowerbound]
higherbound_outliers = df[df[column_name] > upperbound]
outliers = pd.concat([lowerbound_outliers,higherbound_outliers])
normal = df[~ df.index.isin(outliers.index)]
return normal