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

Pandas透视表筛选报错AttributeError:DataFrame无Supply属性求解

问题分析与解决方法

需求说明

从名为df_IBIAS_mode1_FUN的DataFrame中筛选Supply[V]=2.5的数据,生成透视表:

  • 设置index='Device_ID'
  • 设置columns='Temp(deg)'
  • 设置values='ibias_post_trim[MHz]'

错误代码

df_IBIAS_mode1_FUN[df_IBIAS_mode1_FUN.Supply[V] == 2.5].pivot_table(index='Device_ID', columns='Temp(deg)', values='ibias_post_trim[MHz')

错误信息

AttributeError: 'DataFrame' object has no attribute 'Supply'

错误原因及修正

  1. 列名访问方式错误
    你的列名是Supply[V],包含特殊字符[],无法通过.(点语法)访问DataFrame的列(点语法仅支持符合变量命名规则的列名)。必须用方括号[]包裹完整列名来访问。

  2. values参数字符串语法错误
    'ibias_post_trim[MHz'缺少闭合的],正确写法应为'ibias_post_trim[MHz]'。

修正后的代码

# 分步写法,更易读
filtered_data = df_IBIAS_mode1_FUN[df_IBIAS_mode1_FUN['Supply[V]'] == 2.5]
pivot_table_result = filtered_data.pivot_table(
    index='Device_ID',
    columns='Temp(deg)',
    values='ibias_post_trim[MHz]'
)

# 或者合并为一行
pivot_table_result = df_IBIAS_mode1_FUN[df_IBIAS_mode1_FUN['Supply[V]'] == 2.5].pivot_table(
    index='Device_ID',
    columns='Temp(deg)',
    values='ibias_post_trim[MHz]'
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 13:06:26