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 google.colab import drive | |
drive.mount('/content/drive') |
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
df = df.iloc[10:,:] | |
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
df = df[['Timestamp (YYYY-MM-DDThh:mm:ss)', 'Glucose Value (mg/dL)']] | |
df.rename(columns={ | |
"Timestamp (YYYY-MM-DDThh:mm:ss)": "time", | |
"Glucose Value (mg/dL)": "glucose"}, | |
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
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
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() |
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
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
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
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', |
OlderNewer