Home > Back-end >  Plot DataFrame with Strings into stacked bar chart
Plot DataFrame with Strings into stacked bar chart

Time:10-12

following situation:

I have a dataframe (df) with the following scheme:

Gender AgeGroup
0 m Group1
1 m Group2
2 f Group2
3 f Group1

I want to do a stacked bar chart using pandas & matplotlib, with the age groups on the x axis and the amount of genders on a stacked bar on the y-axis.

I tried plotting it with various:

df.plot.bar(column=["AgeGroup", "Gender"], stacked=True)

But I always get the error that there are no numeric values inside the dataframe, which makes sense, but I am trying to count those.

What would the ideal solution be here?

Thanks!

CodePudding user response:

Use a enter image description here

  • Related