我有一个(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)]
你只能删除整行,而不是像(22,1)这样的单个单元格。如果要删除整个数据行。在
df=测向下降(测向索引[[22]])
相关问题 更多 >
编程相关推荐