0

I've been learning python for a few months now.

My data:

df = pd.DataFrame([('20','0'),('25','1'), ('25','0'),('20','0'),('30','0'),('30','1'),('30','1')], columns = ('age','Death_event'))
df['age'] = df['age'].astype('int')
df['Death_event'] = df['Death_event'].astype('int')

I tried to create a bar chart with this code

plt.hist([df[df.Death_event==0].age, df[df.Death_event==1].age], bins = 1, alpha = 0.5, label = ["no_heart_disease","with heart disease"])
plt.xlabel("age")
plt.ylabel("count")
plt.legend()
plt.show()

This is my output:

Output

I would like to build a bar stacked graph with the years on the x axis divided by bin and the stacked bar with percentage of the death =1 and non_death =0.

Someone can help me? thanks a lot

mosc9575
  • 5,618
  • 2
  • 9
  • 32
  • Please do not post images of your data. This is hard to work with. Try to create a [minimal working example](https://stackoverflow.com/help/minimal-reproducible-example). – mosc9575 Dec 09 '21 at 16:13
  • i fixed it. Thanks for answering me I'm new and it's the first question I ask – Luca Martino Dec 09 '21 at 16:41

0 Answers0