I am trying to plot a bar graph, Sale vs categories. Below is my data frame,
S2PName-Category S2BillDate totSale count
0 Beverages 2020-03-06 4452.62 252
1 Food 2020-03-06 36556.91 774
2 Others 2020-03-06 608.95 99
3 Snacks 2020-03-06 2662.75 139
4 Juice 2020-03-06 2139.49 40
5 IceCream 2020-03-06 135.00 4
6 OOB 2020-03-06 390.00 20
My Code :
data = [go.Bar(x=df['S2PName-Category'].unique(),
y=df[df['S2PName-Category']==category]['totSale'],
name = category) for category in df['S2PName-Category'].unique()]
layout = go.Layout(title='Category wise performance',
xaxis = dict(title = 'Categories', automargin = True),
yaxis = dict(tickprefix= '₹', tickformat=',.2f',type='log',autorange = True),
hovermode = 'closest',
plot_bgcolor = colors['background'],
paper_bgcolor = colors['background'],
font = dict(color = colors['text'])
)
Only Beverages from the category ('S2PName-Category') , ispopulated in x-axis, rest are not getting populated. Can anybody point out what went wrong, and how to solve this ? Thanks !
TRIAL 2 : I was trying out other possibilties, due to list comprehension my bar chart gets grouped, is there a way to get unique categories to be plotted ?
Code :
data = [go.Bar(x=df['S2PName-Category'],
y=df['totSale'],
name = category) for category in df['S2PName-Category'].unique()]
layout = go.Layout(title='Category wise performance',
xaxis = dict(title = 'Categories', automargin = True),
yaxis = dict(tickprefix= '₹', tickformat=',.2f',type='log',autorange = True),
hovermode = 'closest',
plot_bgcolor = colors['background'],
paper_bgcolor = colors['background'],
font = dict(color = colors['text'])
)



y=df[df['S2PName-Category']==category]['totSale'].