How to create a grouped bar chart?

Hi there,

I am trying to create a grouped bar chart using Streamlit, but without any success so far. All I got was a stacked bar chart.

Pandas DataFrame:

Job Stat Revenue Total Income
INV 100.00 150.00
WRK 200.00 250.00
CMP 300.00 350.00
JRB 400.00 450.00

The idea is to have the columns “Revenue” and “Total Income” grouped side by side, showing their respective amounts, like in the picture below:

I have tried Altair, also without any success. Is there any trick to achieve it?

Hi @julio,

Maybe something like the approach below, but with altair per this ref: I haven’t used altair before, so did a quick seaborn example.

import seaborn as sns
import pandas as pd

revenue_df = df.drop('Total Income', axis=1)\
               .rename(columns={'Revenue': 'Value'})\
                   {'Category': list('Revenue', len(df)))}),

total_income_df = df.drop('Revenue', axis=1)\
                    .rename(columns={'Total Income': 'Value'})\
                        {'Category': list('Total Income', len(df)))}),

df_revised = pd.concat([revenue_df, total_income_df])

# Display original df and grouped bar chart
sns.barplot(x="Job Stat", y="Value", hue="Category", data=df_revised)

1 Like