SunHaYu 2021-09-28 04:32 采纳率: 100%
浏览 231
已结题

用Python画箱型图并用IQR方法找到并除去异常值

需要根据现有的数据,画出箱型图,并在箱型图上用IQR方法找到异常值,并将异常值清楚
原题如下:
We want to compare distribution of EEDI an EIV values. We used matplotlib boxplot to draw two boxplots side by side to each other as shown below. We can see many outliers in the Technical Efficiency Values. Let's use IQR method to remove such outliers.

IQR Method: The interquartile range (IQR) is calculated as the difference between the 75th and the 25th percentiles of the data. The IQR method considers observations with values 1.5 times above that of the 25th percentile or above that of the 75th percentile as outliers.

For each dataframe, df_eedi and df_eiv, calculate the lower and upper limit for the Technical Efficiency Value. The lower limit is 1.5 times of IQR below 25th percentile whereas the upper limit is 1.5 times of IQR above 75th percentile.

img

想请教一下,该如何用语句执行IQR,并将异常值去除

  • 写回答

1条回答 默认 最新

  • CSDN专家-HGJ 2021-09-28 16:23
    关注

    这个首先获取两个列数据中的四分位差IQR=Q3-Q1,
    a,b=df['device'].quantile([0.25,0.75])
    IQR=b-a
    获取到IQR,
    然后使用语句:

    df=df[(df['device']>a-1.5*IQR) & (df['device']<b+1.5*IQR)]
    print(df)
    

    剔除掉异常数据。

    如有帮助请采纳。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月6日
  • 已采纳回答 9月28日
  • 创建了问题 9月28日

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog