Python: Plotting percentage in seaborn bar plot

后端 未结 4 1050
离开以前
离开以前 2021-01-14 20:52

For a dataframe

import pandas as pd
df=pd.DataFrame({\'group\':list(\"AADABCBCCCD\"),\'Values\':[1,0,1,0,1,0,0,1,0,1,0]})

I am trying to pl

4条回答
  •  离开以前
    2021-01-14 21:05

    You could use your own function in sns.barplot estimator, as from docs:

    estimator : callable that maps vector -> scalar, optional
    Statistical function to estimate within each categorical bin.

    For you case you could define function as lambda:

    sns.barplot(x='group', y='Values', data=df, estimator=lambda x: sum(x==0)*100.0/len(x))
    

提交回复
热议问题