I am new to bokeh/pandas and trying to plot a trend line by using month-year for x-axis and integer values for y-axis.
My data looks like below:
year_month emp_count
0 2015-09 1450425
1 2015-10 3093811
2 2015-11 3316241
3 2015-12 3308658
4 2016-01 3402191
To plot using bokeh I am converting both columns to ndarray. When i convert year-month column to ndarray, it shows each value as a Period. I have used to_period('M') method to get year_month out of a date column.
temp_df.year_month.values
>>output
array([Period('2015-09', 'M'), Period('2015-10', 'M'),
Period('2015-11', 'M'), Period('2015-12', 'M'),
Period('2016-01', 'M'), Period('2016-02', 'M'),
So when i plot using this data, i get following error:
TypeError: Object of type 'Period' is not JSON serializable
To avoid this error i converted year_month column type to string but i still get the same error. My complete code looks like below:
temp_df.year_month = temp_df.year_month.astype(str)
output_file('trend1.html')
p = figure(title='Employee trend',
plot_width=800,
plot_height=350,
x_axis_label='Month-Year', y_axis_label='No of Employees',
x_axis_type='datetime')
p.line(x= temp_df.year_month,
y = temp_df.emp_count)
show(p)
Does anyone know how to plot year-month on x-axis using bokeh?
