Skip to content

Instantly share code, notes, and snippets.

@ThonyPrice
Last active February 23, 2020 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ThonyPrice/32b5d51ea6dfc000be390deeb5df6c17 to your computer and use it in GitHub Desktop.
Save ThonyPrice/32b5d51ea6dfc000be390deeb5df6c17 to your computer and use it in GitHub Desktop.
Medium - Get started analysing your CGM data
def applyThreshold(val, urgentLow=54, low=70, high=180):
if val > high:
return 'high'
elif val <= high and val >= low:
return 'in_range'
elif val < low and val > urgentLow:
return 'low'
else:
return 'urgent_low';
df['Status'] = df['glucose'].apply(lambda x: applyThreshold(x))
z = df.copy(deep=True)
z = z[z['Status'] == 'in_range'][['Status']]
z = z.resample('D').count()
z = z.apply(lambda x: x/(((24*60)/5)+1))
z = z.drop(z.head(1).index)
z = z.drop(z.tail(1).index)
z.insert(z.shape[1], 'day', z.index.value_counts().sort_index().cumsum())
plt.figure(figsize=(16, 6))
ax = sns.regplot(
data = z,
x ='day',
y ='Status',
ci = 95,
color = '#13ac5f')
_ = ax.set(xlabel='Day', ylabel='Daily in-range-ratio')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment