What does this notebook do?
import pandas as pd
import plotly.express as px
import datetime
# Read in CSV file
df = pd.read_csv('export.csv')
# Remove "time zone offset" from "occurred_at" column and add new "occurred_at_day" column
df['occurred_at_day'] = df['occurred_at'].apply(lambda x: x[:len(x) - 15])
df['occurred_at'] = df['occurred_at'].apply(lambda x: x[:len(x) - 6])
df.head()
class | value | time | length | photo_url | description | occurred_at | body | updated_at | started_at | ended_at | created_by | occurred_at_day | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | GlucoseMeasurement | 100.0 | NaN | NaN | NaN | NaN | 2021-08-15 23:48:06 | NaN | NaN | NaN | NaN | NaN | 2021-08-15 |
1 | GlucoseMeasurement | 99.0 | NaN | NaN | NaN | NaN | 2021-08-15 23:33:06 | NaN | NaN | NaN | NaN | NaN | 2021-08-15 |
2 | GlucoseMeasurement | 99.0 | NaN | NaN | NaN | NaN | 2021-08-15 23:18:06 | NaN | NaN | NaN | NaN | NaN | 2021-08-15 |
3 | GlucoseMeasurement | 98.0 | NaN | NaN | NaN | NaN | 2021-08-15 23:03:06 | NaN | NaN | NaN | NaN | NaN | 2021-08-15 |
4 | GlucoseMeasurement | 97.0 | NaN | NaN | NaN | NaN | 2021-08-15 22:48:06 | NaN | NaN | NaN | NaN | NaN | 2021-08-15 |
# Print all days with data
daysWithData = df['occurred_at_day'].unique()
print(daysWithData)
['2021-08-15' '2021-08-14' '2021-08-13' '2021-08-12' '2021-08-11' '2021-08-10' '2021-08-09' '2021-08-08' '2021-08-07' '2021-08-06' '2021-08-05']
# Filter down to one day, pick the second day in the dataset
day = daysWithData[1]
df = df[df['occurred_at_day']==day]
# Create a datasets just with glucose measurments
gm = df[df['class']=='GlucoseMeasurement']
# Only keep the columns that we need
gm_data = gm.filter(['occurred_at', 'value'])
# rename the columns for easier readability
gm_data.columns = ['time', 'value']
# turn time column into the index and delete time column
gm_data['time']= pd.to_datetime(gm_data['time'])
gm_data.index = gm_data['time']
del gm_data['time']
gm_data = gm_data.resample('1T').mean() # add rows for every 1 minute
gm_data = gm_data.interpolate(method='cubic') # interpolate the new 1 minute points with data
# Chart the data
fig = px.line(gm_data, y="value")
# Add axis titles
fig.update_xaxes(title_text=str(day), tickformat='%H:%M')
fig.update_yaxes(title_text='mg/dL')
fig.show()