I am trying to plot a line chart. Below is my code
CODE :
import plotly.offline as pyo
import plotly.graph_objects as go
flag = determineFlag('2020-03-01','2020-03-30')
df_r = getDataForTrend(df,'2020-03-01','2020-03-30','d')
colors = {
'background': '#111111',
'text': '#7FDBFF'
}
data = [go.Scatter(x = df_r[df_r['S2PName-Category']==category]['S2BillDate'],
y = df_r[df_r['S2PName-Category']==category]['totSale'],
mode = 'lines',
name = category) for category in df_r['S2PName-Category'].unique()]
layout = {'title':'Category Trend',
'xaxis':{'title':'Time Frame'},
'yaxis':{'title':'Total Sales Amount','tickformat' : '.2f'}}
fig = go.Figure(data=data,layout=layout)
pyo.iplot(fig)
when I run the above code I get the below error:
ERROR:
TypeError: Object of type Period is not JSON serializable
While tying to debug, I try to execute the below code
DEBUG CODE :
df_r[df_r['S2PName-Category']==category]['S2BillDate']
OP :
3 2020-03-01
11 2020-03-02
21 2020-03-03
26 2020-03-04
41 2020-03-06
42 2020-03-05
46 2020-03-07
Name: S2BillDate, dtype: period[D]
How can I fix the type error ? Is there any tweaks to this ? Any help is much appreciated! Thanks !