1

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()
rerecodes
  • 33
  • 5
  • 1
    Please post your data in text format, not as a screenshot, so that we can reproduce your problem. You can run `gdp.head(10).to_dict()` (also see [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391)). Also post your full error traceback message. – AlexK Mar 07 '23 at 06:06

1 Answers1

0

Try:

fig = px.bar(gdp, x = gdp['UN Region', 'UN Region'],
                  y = gdp['IMF[1][13]', 'Estimate'],
                  color = gdp['Country/Territory', 'Country/Territory'])
Corralien
  • 109,409
  • 8
  • 28
  • 52