Answers for "numpy remove outliers"

5

remove outliers python pandas

#------------------------------------------------------------------------------
# accept a dataframe, remove outliers, return cleaned data in a new dataframe
# see http://www.itl.nist.gov/div898/handbook/prc/section1/prc16.htm
#------------------------------------------------------------------------------
def remove_outlier(df_in, col_name):
    q1 = df_in[col_name].quantile(0.25)
    q3 = df_in[col_name].quantile(0.75)
    iqr = q3-q1 #Interquartile range
    fence_low  = q1-1.5*iqr
    fence_high = q3+1.5*iqr
    df_out = df_in.loc[(df_in[col_name] > fence_low) & (df_in[col_name] < fence_high)]
    return df_out
Posted by: Guest on April-27-2021
0

remove outliers python pandas

df = pd.DataFrame(np.random.randn(100, 3))

from scipy import stats
df[(np.abs(stats.zscore(df)) < 3).all(axis=1)]
Posted by: Guest on November-27-2020
0

remove outliers numpy array

import numpy as np
from scipy import stats
a = np.array([1,1,1,1,1,1,1,1,1,100])
a_no_outliers = a[(np.abs(stats.zscore(a)) < 3)]
print(a_no_outliers)
out: array([1, 1, 1, 1, 1, 1, 1, 1, 1])
Posted by: Guest on January-10-2022

Python Answers by Framework

Browse Popular Code Answers by Language