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 = df.copy(deep=True) | |
df['time'] = pd.to_datetime(df['time']) | |
df['time'] = df['time']\ | |
.dt.tz_localize(tz='UTC')\ | |
.dt.tz_convert('US/Pacific') | |
df.set_index('time', inplace=True) | |
df.head() |
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.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 = 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['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
import pandas as pd | |
df = pd.read_csv('drive/My Drive/my-cgm-exploration/Example_CGM_data.csv') | |
df.head(20) |
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
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 |
NewerOlder