I am trying to answer in haberman dataset (https://www.kaggle.com/gilsousa/habermans-survival-data-set)
- what % of the people survive in various age brackets
I have taken following steps after getting data in pandas dataframe 'data'. Not able to create calculated column which has '% survived'. % survived = total survived / total in that age group.
print(data.head(3))
age year nodes status
0 30 64 1 1
1 30 62 3 1
2 30 65 0 1
data['age group'] = pd.cut(data.age,range(25,85,5))
table = data.pivot_table(index =['age group'], columns = ['status'], values='year',aggfunc=np.count_nonzero).fillna(0)
table.reset_index(level=0, inplace=True)
table['surv_pc'] = table.iloc[:,1]/(table.iloc[:,1]+table.iloc[:,2])*100
sns.set_theme(style="whitegrid")
bar = sns.barplot(data=table, x='age group',y='surv_pc')
the type of graph is matplotlib.axes._subplots.AxesSubplot
How do i access the bar heights so that i can put labels as per plot.text() method ?
As per documentation of
https://matplotlib.org/3.1.0/api/axes_api.html?highlight=matplotlib#matplotlib.axes.Axes, it returns Axes
object only. Please help understand...