You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python调用pandas quantile报'method' object is not subscriptable如何解决

问题原因
  • 报错TypeError: 'method' object is not subscriptable的核心原因是:pandas中Series的quantile是可调用的方法,不是可以用方括号下标索引的属性/字典对象,你代码中用quantile['25%']的写法不符合语法要求。
修复方案

把quantile后的方括号替换为圆括号,参数传入对应分位数的浮点数值即可:25%分位传入0.25,75%分位传入0.75。

修正后完整代码
def detect_outliers(df, x):
    Q1 = df[x].quantile(0.25)
    Q3 = df[x].quantile(0.75)
    IQR = Q3 - Q1
    return df[(df[x] < Q1 - 1.5*IQR) | (df[x] > Q3 + 1.5*IQR)]

detect_outliers(df, 'SepalWidthCm')

内容的提问来源于stack exchange,提问作者Manisha Elok

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 22:36:04