TransWikia.com

Stacked bar graph from multiple columns in Pandas DataFrame

Stack Overflow Asked by iisnaam on January 14, 2021

I’m trying to do a stacked bar graph. This is my dataframe:
DataFrame

I want the male and female columns stacked by year. How do I go about doing it.

I’ve tried

plotdata = yearly_data.DataFrame({"male", "female"},index = "year")
plotdata.plot(kind="bar")
data = data.set_index('year')
data[["male", "female"]].plot(kind="bar")
plt.show()

I’ve even tried filtering by just one year to see if I can at least do an unstacked bar graph:

year = 2018
year_2018 = data.loc[year] 
plot_2018 = year_2018.plot(kind = "bar")
plt.show()

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP