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

用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 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答