0

I have an error with the datatype in my pandas dataframe which is preventing matplotlib from being able to create a bar chart.

I understand to fix this I need the code dtype=object but I cannot find in the documentation where this goes. Please help.

plt.figure(figsize=(20,5))
plt.title("Population by State", fontsize=14)
plt.bar(x=uspop_pd.index, y=uspop_pd['POPESTIMATE2019'], height = 1)

plt.xlabel("State")
plt.ylabel("Population vs Customers") 
dtype=object
plt.show()
  • `uspop_pd['POPESTIMATE2019'].astype("object")`? However, what makes you think that this will fix your problem? What is the specific problem arising from your data? – Mr. T Jan 17 '22 at 12:27
  • `y=uspop_pd['POPESTIMATE2019'].astype(float)` ? You might want to add the exact error message and the output of `uspop_pd.info()` to your post. – JohanC Jan 17 '22 at 12:56
  • .astype("object") gives the error message: ValueError: setting an array element with a sequence. – Pomegranate Molasses Jan 17 '22 at 12:59
  • As Johan and I were telling you, you did not specify the problem. Your question determines the answers. Please read [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Mr. T Jan 17 '22 at 13:06

0 Answers0