【问题标题】:Remove outliers by group based on IQR基于 IQR 按组去除异常值
【发布时间】:2018-09-10 08:29:28
【问题描述】:

我有一个包含以下变量的 df:

  • pp(参与者)
  • 条件
  • rt(反应时间)

(以及一大堆其他东西)。

我想根据 iqr 标准修剪异常值。但是,我想根据条件,每页这样做。

我认为解决方案将从

开始
grouped = df.groupby(['pp','condition'])

然后呢?如何删除每组的异常值?我是使用应用功能,还是过滤功能在这里帮助我?

【问题讨论】:

  • 提供样本数据和预期输出

标签: python pandas pandas-groupby outliers


【解决方案1】:

你可以这样做:

# define a function to filter out your data
def filter_condition(grped_df):
    if some_condition:
        return grped_df[some_condition]
    return grped_df


grouped = df.groupby(by=['pp','condition'])

# use apply to pass each group to your defined function and reset index to remove grouped multi index.

filtered_df = grouped.apply(filter_condition).reset_index(drop=True)

【讨论】:

  • 是的,做到了。感谢您的提示!
猜你喜欢
  • 2015-01-23
  • 1970-01-01
  • 1970-01-01
  • 2018-12-05
  • 2020-05-06
  • 2023-03-21
  • 1970-01-01
  • 2020-04-09
相关资源
最近更新 更多