Last active
May 14, 2019 14:09
-
-
Save cobanov/a8d46c59ca332b01736cdca3b763000c to your computer and use it in GitHub Desktop.
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
import pandas as pd | |
import numpy as np | |
d = {'col1': [1, 2, 3, 4, 5, 6, 100], 'col2': [ 2, 4, 6, 8, 10, 12, 200]} | |
df = pd.DataFrame(d) | |
print(df) | |
def detect_outlier(df, threshold): | |
outliers = [] | |
means = [] | |
stds = [] | |
for i in range(0,len(df.columns)): | |
means.append(np.mean(df.iloc[:,i])) | |
stds.append(np.std(df.iloc[:,i])) | |
for df_value in df.iloc[:,i]: | |
z_score = (df_value - means[i]) / stds[i] | |
if np.abs(z_score) > threshold: | |
outliers.append(df_value) | |
return outliers, means, stds | |
print(detect_outlier(df, threshold = 2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Mr. Cobanov !