0
votes

I have Dataframe

Date        Category    Sum
2019-06-03    "25M"      34
2019-06-03    "25M"      60
2019-06-03    "50M"      23
2019-06-04    "25M"      67
2019-06-05    "50M"     -90
2019-06-05    "50M"     100
2019-06-06    "100M"     6
2019-06-07    "25M"     -100
2019-06-08    "100M"     67
2019-06-09    "25M"      450
2019-06-10    "50M"      600
2019-06-11    "25M"      -9
2019-07-12    "50M"      45
2019-07-13    "50M"      67
2019-07-14    "100M"    130
2019-07-14    "50M"      45
2019-07-15    "100M"    100
2019-07-16    "25M"     -90
2019-07-17    "25M"     700
2019-07-18    "25M"     -9

First, I will group my date and Category with Sum so that I get the data frame like this.

df.groupby(["EntryDate","Category"]).agg({"NetProfit":"sum"}).reset_index()

 Date         Category   Sum
2019-06-03    "25M"      94
2019-06-03    "50M"      23
2019-06-04    "25M"      67
2019-06-05    "50M"      10
2019-06-06    "100M"     6     ...and so on     

I want to create plotly Time Series grouped bar graph so that it will show me 3 bars for "25M", "50M" and "100M" on the respective date in PLotly.

1

1 Answers

1
votes

I think you'd want to use a standard bar chart and add an entry for 25M, 50M, and 100M, something like:

import plotly.graph_objects as go

fig = go.Figure(data=[
    go.Bar(name='25M', x=df.EntryDate[df.Category=='25M'], y=df.NetProfit[df.Category=='25M']),
    go.Bar(name='50M', x=df.EntryDate[df.Category=='50M'], y=df.NetProfit[df.Category=='50M']),
    go.Bar(name='100M', x=df.EntryDate[df.Category=='100M'], y=df.NetProfit[df.Category=='100M'])
])

fig.show()

Or, in a loop:

import plotly.graph_objects as go

AMT=['25M','50M','100M']

fig = go.Figure()
for i in AMT:
    fig.add_trace(go.Bar(name=i, 
                         x=df.EntryDate[df.Category==i], 
                         y=df.NetProfit[df.Category==i],
                        )
                 )

fig.show()

enter image description here