Python: Plotting percentage in seaborn bar plot

后端 未结 4 1086
离开以前
离开以前 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:27

    You can use Pandas in conjunction with seaborn to make this easier:

    import pandas as pd
    import seaborn as sns
    
    df = sns.load_dataset("tips")
    x, y, hue = "day", "proportion", "sex"
    hue_order = ["Male", "Female"]
    
    (df[x]
     .groupby(df[hue])
     .value_counts(normalize=True)
     .rename(y)
     .reset_index()
     .pipe((sns.barplot, "data"), x=x, y=y, hue=hue))
    

提交回复
热议问题