I'm new to python and was wondering how to create a barplot on this data I created using pivot table function.
#Create a pivot table for handicaps count calculation for no-show people based on their gender
pv = pd.pivot_table(df_main, values=['hipertension','diabetes','alcoholism'],
columns='status',index='gender',aggfunc=np.sum)
#Reshape the pivot table for easier calculation
data_pv = pv.unstack().unstack('status').reset_index().rename(columns={'level_0':'category','No-Show':'no_show', 'Show-Up':'show_up'})
data_pv['no_show_prop'] = (data_pv['no_show']/
(data_pv['no_show']+data_pv['show_up']))*100
data_pv
And as a result:
status category gender no_show show_up no_show_prop
0 alcoholism F 308 915 25.183974
1 alcoholism M 369 1768 17.267197
2 diabetes F 1017 4589 18.141277
3 diabetes M 413 1924 17.672229
4 hipertension F 2657 12682 17.321859
5 hipertension M 1115 5347 17.254720
I want to create a bar graph with category as x-axis and no_show_prop as y-axis with two different colors bars indicate female and male for each category. I also tried using groupby but it's not come out as I wanted to be.
Instead of bar like in this picture below, I want to create a bar graph with category as x-axis and no_show_prop as y-axis with two different colors bars indicate female and male for each category. I also tried using groupby but it's not come out as I wanted to be.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…