'Creating a stacked bar chart from two data columns

enter image description here

Attached is a picture of the dataframe I am working with. I am trying to create a stacked bar chart. My x-axis should be "APGAR5" scores (0-9) with the frequency count. For each bar, it should be stacked based on the column "Pregnancy_Type".

question5, subplot05 = plt.subplots(1,1)
births_complete["Pregnancy_Type"].value_counts().sort_index().plot.bar(x=births_complete["APGAR5"], ax=subplot05)
births_complete["APGAR5"].value_counts().sort_index().plot.bar(ax=subplot05)
#subplot05 = births_complete[["APGAR5", "Pregnancy_Type"]].plot(kind="bar", stacked=True)

This has been my attempts so far, I am able to create a standard bar chart, but I am having trouble making it stacked based on categorical data.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source