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:
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