In [1]:
import pandas as pd

In [2]:
from bokeh.sampledata.glucose import data
from bokeh.plotting import figure, show, output_notebook

In [3]:
output_notebook()


BokehJS successfully loaded.

In [4]:
from bokeh.sampledata.glucose import data

In [5]:
data.to_csv('glucose.csv')

In [6]:
pd.read_csv('glucose.csv', index_col='datetime')


Out[6]:
isig glucose
datetime
2010-03-24 09:51:00 22.59 258
2010-03-24 09:56:00 22.52 260
2010-03-24 10:01:00 22.23 258
2010-03-24 10:06:00 21.56 254
2010-03-24 10:11:00 20.79 246
2010-03-24 10:16:00 19.97 238
2010-03-24 10:21:00 19.35 230
2010-03-24 10:26:00 18.86 224
2010-03-24 10:31:00 18.15 216
2010-03-24 10:36:00 17.6 210
2010-03-24 10:41:00 17.3 204
2010-03-24 10:46:00 16.83 198
2010-03-24 10:51:00 16.25 192
2010-03-24 10:56:00 15.73 186
2010-03-24 11:01:00 15.19 180
2010-03-24 11:06:00 14.63 174
2010-03-24 11:11:00 14.05 158
2010-03-24 11:16:00 13.53 152
2010-03-24 11:21:00 13.07 146
2010-03-24 11:26:00 12.79 142
2010-03-24 11:31:00 12.53 138
2010-03-24 11:36:00 12.14 136
2010-03-24 11:41:00 11.51 130
2010-03-24 11:46:00 10.59 122
2010-03-24 11:51:00 9.64 114
2010-03-24 11:56:00 9.37 106
2010-03-24 12:01:00 9.78 106
2010-03-24 12:06:00 10.26 108
2010-03-24 12:11:00 10.68 112
2010-03-24 12:16:00 11.04 116
... ... ...
2010-10-10 21:32:00 18.54 120
2010-10-10 21:37:00 17.24 109
2010-10-10 21:42:00 18.56 102
2010-10-10 21:47:00 22.8 112
2010-10-10 21:52:00 26 127
2010-10-10 21:57:00 28.6 142
2010-10-10 22:02:00 30.18 155
2010-10-10 22:07:00 31.02 164
2010-10-10 22:12:00 31.78 170
2010-10-10 22:17:00 31.18 171
2010-10-10 22:22:00 30.88 171
2010-10-10 22:27:00 30.92 171
2010-10-10 22:32:00 30.46 169
2010-10-10 22:37:00 29.46 166
2010-10-10 22:42:00 28.56 162
2010-10-10 22:47:00 28.32 158
2010-10-10 22:52:00 28.46 157
2010-10-10 22:57:00 28.5 157
2010-10-10 23:02:00 28.34 156
2010-10-10 23:07:00 28.1 156
2010-10-10 23:12:00 28.02 155
2010-10-10 23:17:00 28.06 155
2010-10-10 23:22:00 28.2 155
2010-10-10 23:27:00 28.4 155
2010-10-10 23:32:00 29.26 158
2010-10-10 23:37:00 29.46 160
2010-10-10 23:42:00 29.08 160
2010-10-10 23:47:00 29.06 160
2010-10-10 23:52:00 29.3 161
2010-10-10 23:57:00 30.8 165

52281 rows × 2 columns


In [7]:
p1 = figure(x_axis_type="datetime")

p1.line(data.index, data['glucose'], color='red', legend='glucose')
p1.line(data.index, data['isig'], color='blue', legend='isig')

p1.title = "Glucose Measurements"

show(p1)



In [8]:
day = data.ix['2010-10-06']
highs = day[day['glucose'] > 180]
lows = day[day['glucose'] < 80]

p2 = figure(x_axis_type="datetime")

p2.line(day.index, day['glucose'], line_color="gray", line_dash="4 4", line_width=1, legend="glucose")
p2.scatter(highs.index, highs['glucose'], size=6, color='tomato', legend="high")
p2.scatter(lows.index, lows['glucose'], size=6, color='navy', legend="low")

p2.title = "Glucose Range"
p2.xgrid.grid_line_color=None
p2.ygrid.grid_line_alpha=0.5

show(p2)



In [9]:
data['inrange'] = (data['glucose'] < 180) & (data['glucose'] > 80)
window = 30.5*288 #288 is average number of samples in a month
inrange = pd.rolling_sum(data.inrange, window)
inrange = inrange.dropna()
inrange = inrange/float(window)

p3 = figure(x_axis_type="datetime")

p3.line(inrange.index, inrange, line_color="navy")

p3.title = "Glucose In-Range Rolling Sum"

show(p3)