Seaborn multiple barplots

前端 未结 2 1490
猫巷女王i
猫巷女王i 2021-02-01 15:26

I have a pandas dataframe that looks like this:

    class       men       woman   children
0   first   0.91468    0.667971   0.660562
1   second  0.30012    0.32         


        
2条回答
  •  独厮守ぢ
    2021-02-01 15:46

    I know my answer came very late but I hope someone benefit from it.

    to solve the above I used the below code after re-arranging the data of course:

    Data:

    d = {'class': ['first', 'second', 'third', 'first', 'second', 'third', 'first', 'second', 'third'], 'sex': ['men', 'men', 'men', 'woman', 'woman', 'woman', 'children', 'children', 'children'], 'survival_rate':[0.914680, 0.300120, 0.118990, 0.667971, 0.329380, 0.189747, 0.660562, 0.882608, 0.121259]} 
    
    df = pd.DataFrame(data=d)
    

    sns.factorplot("sex", "survival_rate", col="class", data=df, kind="bar")
    

提交回复
热议问题