Black Lives Matter. Please consider donating to Black Girls Code today.

How to plot bar plot from groupby values?

Hello Everyone

I wanted to know if there was a possibility to plot bar plots from groupby values using plotly?
Using matplotlib that’s how i did it

import matplotlib.pyplot as plt
Grouped_D = Dataset.groupby('Dept')['Weekly_Sales'].sum()

And that’s what i get

Any help would be much appreciated , thank you

Hi @Midi welcome to the forum! The easiest thing is probably to use plotly express functions since they take care of the groupby operation for you:

import as px
df =
fig =, x='day', y='tip')


import as px
df =
fig = px.histogram(df, x='day', y='tip', histfunc='sum')

(with histogram you will get one bar, where as with bar you will get one bar per line of the dataframe).
Of course you can also do the groupby yourself and then call px.par or go.Bar:

import plotly.graph_objects as go
df =
dfg = df.groupby('day')['tip'].sum()
fig =, y=dfg)
# also works with graph_objects:
# fig = go.Figure(go.Bar(x=dfg.index, y=dfg))