Last active
February 23, 2020 05:14
-
-
Save ThonyPrice/32b5d51ea6dfc000be390deeb5df6c17 to your computer and use it in GitHub Desktop.
Medium - Get started analysing your CGM data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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