Bar plot of groupe.size data from Pandas dataframe

Hi, Sorry about the double post, but this was also posted in Dash. I think I posted this should have been posted here.

Not sure if I need the plotly package or Cufflinks for this, but the examples that I have seen from both Dash and Plotly, it is not clear to me how to display groupy data as bar chart.

My code is as follows:

import pandas as pd
df = pd.read_excel(‘test.xlsx’,sheet_name=‘Sheet1’)
dfstate = df.groupby(‘State’)
df3 = dfstate.size()

my df3 data looks like this:
State
Done 3
Plot Phase 4
Script Phase 2
TRS Phase 2
TRS Review Phase 3

So I want to display the data above as a bar chart. So not sure how df3 in ‘data’ need to be presented in figure. Maybe I am overcomplicating this and the answer is right in front of me based on other examples.

dcc.Graph(id=‘plot1’,
figure = {
‘data’ : df3 , ‘layout’ : {
‘title’ : ‘TestState’,
‘xaxis’: {‘title’: ‘Review States’}, ‘yaxis’ :
{‘title’ : ‘Completion status’}
}}}

Hi Gus,

I think you can get it to work if you explicitly separate the x-axis data and the y-axis data in your dataframe.

import plotly.graph_objs as go

data = [go.Bar(x=df3.index,y=df3)]

layout = go.Layout(title=‘TestState’,
xaxis=dict(title=‘Review States’),
yaxis=dict(title=‘Completion Status’)
)

figure= go.Figure(data=data,layout=layout)

Michael,

I figured that it would require rearranging the dataframe.
I will consider your approach and experiment with it.

Thanks,
Gus