Georg Heiler
Georg Heiler

Reputation: 17676

Seaborn visualize groups

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) enter image description here But rather like this per KPI enter image description here

Upvotes: 0

Views: 505

Answers (1)

Abdou
Abdou

Reputation: 13274

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!

Upvotes: 1

Related Questions