Group by hours and plot in Bokeh

2020-05-01 06:27发布

I am trying to get a plot like a stock data in Bokeh like in the link http://docs.bokeh.org/en/latest/docs/gallery/stocks.html

2004-01-05,00:00:00,01:00:00,Mon,20504,792
2004-01-05,01:00:00,02:00:00,Mon,16553,783
2004-01-05,02:00:00,03:00:00,Mon,18944,790
2004-01-05,03:00:00,04:00:00,Mon,17534,750
2004-01-06,00:00:00,01:00:00,Tue,17262,747
2004-01-06,01:00:00,02:00:00,Tue,19072,777
2004-01-06,02:00:00,03:00:00,Tue,18275,785

I want to use column 2:startTime and 5:count and I want to group by column day and sum the counts in respective hours.

code: Does not give the output

import numpy as np
import pandas as pd
#from bokeh.layouts import gridplot
from bokeh.plotting import figure, show, output_file

data = pd.read_csv('one_hour.csv')
data.column = ['date', 'startTime', 'endTime', 'day', 'count', 'unique']

p1 = figure(x_axis_type='startTime', y_axis_type='count', title="counts per hour")
p1.grid.grid_line_alpha=0.3
p1.xaxis.axis_label = 'startTime'
p1.yaxis.axis_label = 'count'

output_file("count.html", title="time_graph.py")
show(gridplot([[p1]], plot_width=400, plot_height=400))  # open a browser

Reading the column and plot isn't any problem but applying group by and sum operations on the column data is something I am not able to perform.

Appreciate the help, Thanks !

1条回答
干净又极端
2楼-- · 2020-05-01 06:42

Sounds like this is what you need:

data.groupby('startTime')['count'].sum()

Output:

00:00:00    37766
01:00:00    35625
02:00:00    37219
03:00:00    17534
查看更多
登录 后发表回答