how to use pandas filter with IQR?

前端 未结 6 1009
迷失自我
迷失自我 2020-12-28 13:17

Is there a built-in way to do filtering on a column by IQR(i.e. values between Q1-1.5IQR and Q3+1.5IQR)? also, any other possible generalized filtering in pandas suggested

6条回答
  •  梦谈多话
    2020-12-28 14:06

    Another approach using Series.between():

    iqr = df['col'][df['col'].between(df['col'].quantile(.25), df['col'].quantile(.75), inclusive=True)]
    

    Drawn out:

    q1 = df['col'].quantile(.25)
    q3 = df['col'].quantile(.75)
    mask = d['col'].between(q1, q3, inclusive=True)
    iqr = d.loc[mask, 'col']
    

提交回复
热议问题