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

用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日

悬赏问题

  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
  • ¥15 下列c语言代码为何输出了多余的空格