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.join(pd.get_dummies(z['Status']), how='left') | |
day_map = ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun'] | |
z['weekday'] = z.index.weekday | |
z = z[['weekday', 'glucose']] | |
z = z.resample('D').mean() | |
z['chunk'] = 'Second' | |
z['chunk'].iloc[:(z.shape[0]//2)] = 'First' | |
z.sort_values(['weekday', 'chunk'], inplace=True) |
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['day'] = z.index.date | |
z['day_time'] = z.index.round('5Min').time | |
z = z[['day', 'day_time', 'glucose']] | |
z = z.groupby(['day', 'day_time']).last() | |
z = z.reset_index() | |
_ = plt.figure(figsize=(20, 8)) | |
x_cmap = sns.diverging_palette(220, 20, n=9) | |
f = sns.heatmap(z.pivot('day_time', 'day', 'glucose'), cmap=x_cmap, vmin=0, vmax=300) |
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.join(pd.get_dummies(z['Status']), how='left') | |
day_map = ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun'] | |
z['weekday'] = z.index.weekday | |
z = z[['weekday', 'glucose']] | |
z = z.resample('D').mean() | |
z.sort_values('weekday', inplace=True) | |
z.dropna(inplace=True) | |
z['weekday'] = z['weekday'].apply(lambda x: day_map[int(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.index = z.index.round('5Min') | |
plt.figure(figsize=(16, 6)) | |
ax = sns.lineplot(x=z.index.time, y=z['glucose'], color='#13ac5f') |
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'; |
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.resample('D').mean() | |
z['date'] = z.index.date | |
z.insert(z.shape[1], 'day', z.index.value_counts().sort_index().cumsum()) | |
plt.figure(figsize=(16, 6)) | |
fs = sns.regplot( | |
data = z, | |
x ='day', | |
y ='glucose', |
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
df['glucose'] = df['glucose'].astype(int) | |
_ = sns.distplot(df['glucose']) | |
df.describe() |
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
expected_diff = timedelta(minutes=5, seconds=30) | |
missing_samples_idxs = np.where(z['t_diff'] > expected_diff)[0] | |
c_samples_times = z.iloc[missing_samples_idxs, :]['t_diff'] | |
c_samples_times |
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
# Inspect samples closer than average | |
import numpy as np | |
import matplotlib.pyplot as plt | |
expected_diff = timedelta(minutes=4, seconds=30) | |
close_samples_idxs = np.where(z['t_diff'] < expected_diff)[0] | |
c_samples_times = z.iloc[close_samples_idxs, :]['t_diff'] | |
c_samples_times = c_samples_times.apply(lambda x: x.seconds) |
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
from datetime import datetime, date | |
z = df.copy(deep=True) | |
z['t1'] = z.index | |
z['t2'] = z['t1'].shift(1) | |
z['t_diff'] = z['t1'] - z['t2'] | |
z['t_diff'].describe() |
NewerOlder