0
我有一個(268X4)df,並找到一列的異常值(22,1)。我想從df中刪除那些異常值。我怎麼做?如何從數據框中刪除異常值?
> df=df_nonull import pandas as pd # to manipulate dataframes import
> numpy as np # to manipulate arrays
>
> # a number "a" from the vector "x" is an outlier if
> # a > median(x)+1.5*iqr(x) or a < median-1.5*iqr(x)
> # iqr: interquantile range = third interquantile - first interquantile def
>outliers(x):
> return np.abs(x- x.median()) > 1.5*(x.quantile(.75)-
>x.quantile(0.25))
>
> # Give the outliers for the first column for example
>outliers=df.StockValue[outliers(df.StockValue)]