hasattr():属性名必须是字符串

huangapple go评论60阅读模式
英文:

hasattr(): attribute name must be string

问题

I am trying to make a stacked bar plot in plotly using webscraping. However, I keep getting this error: "hasattr(): attribute name must be string". I think it might be the part: "gdp['IMF[1][13]', 'Estimate']" that is causing the error.

This is what the dataframe looks like:
enter image description here

import plotly.express as px
ERROR -> fig = px.bar(gdp, x = gdp['UN Region'], y = gdp['IMF[1][13]', 'Estimate'], color = gdp['Country/Territory'])
fig.show()
英文:

I am trying to make a stacked bar plot in plotly using webscraping. However, I keep getting this error: "hasattr(): attribute name must be string". I think it might be the part:"gdp['IMF[1][13]', 'Estimate']" that is causing the error.

This is what the dataframe looks like:
enter image description here

import plotly.express as px
ERROR -> fig = px.bar(gdp, x = gdp['UN Region'], y = gdp['IMF[1][13]', 'Estimate'], color = gdp['Country/Territory'])
fig.show()

答案1

得分: 0

尝试:

fig = px.bar(gdp, x = gdp['UN Region', 'UN Region'],
                  y = gdp['IMF[1][13]', 'Estimate'],
                  color = gdp['Country/Territory', 'Country/Territory'])
英文:

Try:

fig = px.bar(gdp, x = gdp['UN Region', 'UN Region'],
                  y = gdp['IMF[1][13]', 'Estimate'],
                  color = gdp['Country/Territory', 'Country/Territory'])

huangapple
  • 本文由 发表于 2023年3月7日 12:26:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75658035.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定