【问题标题】:How to remove outliers from a dataframe?如何从数据框中删除异常值?
【发布时间】:2017-10-26 19:59:23
【问题描述】:

我有一个 (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)] 

【问题讨论】:

    标签: python statistics data-science outliers


    【解决方案1】:

    您只能删除整行,而不是像 (22,1) 这样的单个单元格。如果要删除整行数据。

    df = df.drop(df.index[[22]])

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-22
      • 2018-03-23
      • 1970-01-01
      • 2011-06-14
      • 2018-01-09
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多