Seaborn visualize groups

[亡魂溺海] 提交于 2019-12-25 07:59:17

问题


How can I plot this data frame using seaborn to show the KPI per model?

allFrame = pd.DataFrame({'modelName':['first','second', 'third'],
                           'kpi_1':[1,2,3],
                           'kpi_2':[2,4,3]})

Not like sns.barplot(x="kpi2", y="kpi1", hue="modelName", data=allFrame) But rather like this per KPI


回答1:


Try melting the dataframe first, and then you can plot using seaborn:

import pandas as pd
import seaborn as sns

allFrame = pd.DataFrame({'modelName':['first','second', 'third'],
                           'kpi_1':[1,2,3],
                           'kpi_2':[2,4,3]})
allFrame2 = pd.melt(frame=allFrame, 
                          id_vars=['modelName'], 
                          value_vars=["kpi_1","kpi_2"], 
                          value_name="Values", var_name="kpis")

sns.barplot(x="kpis", y="Values", hue="modelName", data=allFrame2)

Thanks!



来源:https://stackoverflow.com/questions/39679431/seaborn-visualize-groups

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!