“Hapus outlier python dataframe” Kode Jawaban

Hapus outlier python panda

#------------------------------------------------------------------------------
# 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
Handsome Hawk

Hapus outlier python dataframe

cols = ['col_1', 'col_2'] # one or more

Q1 = df[cols].quantile(0.25)
Q3 = df[cols].quantile(0.75)
IQR = Q3 - Q1

df = df[~((df[cols] < (Q1 - 1.5 * IQR)) |(df[cols] > (Q3 + 1.5 * IQR))).any(axis=1)]
Bored Butterfly

Pandas Penghapusan Pencilan

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

from scipy import stats
df[(np.abs(stats.zscore(df)) < 3).all(axis=1)]
Frantic Fox

PANDAS Menghapus outlier dari DataFrame

df[(df["col"] >= x ) & (df["col"] <= y )]

but it's more readable to use:

df[df["col"].between(x,y)]
rudythealchemist

Jawaban yang mirip dengan “Hapus outlier python dataframe”

Pertanyaan yang mirip dengan “Hapus outlier python dataframe”

Lebih banyak jawaban terkait untuk “Hapus outlier python dataframe” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya