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

解决DataFrame对象无Vmax属性的AttributeError问题

解决Matplotlib绘图时的AttributeError: 'DataFrame' object has no attribute 'Vmax'错误

问题代码

plt.figure(figsize = (15,5))

plt.plot(data.indice_tiempo, data.Vmax, label = 'Precio máximo')
plt.plot(data.indice_tiempo, data.Vmin, label = 'Precio mínimo')
plt.legend()
plt.xlabel('Fecha')
plt.ylabel('Precio')
#plt.ylim(-10,40)
plt.show()

完整报错回溯

AttributeError                            Traceback (most recent call last)
<ipython-input-28-e6aa3f72c6f3> in <module>
      1 plt.figure(figsize = (15,5))
      2 
----> 3 plt.plot(data.indice_tiempo, data.Vmax, label = 'Precio máximo')
      4 #plt.plot(data.indice_tiempo, data.Vmin, label = 'Precio mínimo')
      5 plt.legend()

/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py in __getattr__(self, name)
   5485         ):
   5486             return self[name]
-> 5487         return object.__getattribute__(self, name)
   5488 
   5489     def __setattr__(self, name: str, value) -> None:

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

解决方案

  • 先确认DataFrame的实际列名:执行print(data.columns)查看所有列的名称,检查是否存在Vmax和Vmin。常见问题是列名拼写错误(比如大小写不一致、名称缩写不同,比如实际是vmax、MaxPrice等)。
  • 修正代码中的列引用:如果列名不是Vmax/Vmin,改用方括号索引的方式调用列(这种方式兼容性更强,适合列名含空格或特殊字符的情况)。比如实际列名是vmax,则将data.Vmax改为data['vmax']。
  • 验证数据加载是否正确:如果数据来自外部文件(如CSV),检查读取代码(比如pd.read_csv)是否指定了正确的分隔符,是否遗漏了列,或者文件本身是否包含目标数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 11:16:56