Skip to content

Instantly share code, notes, and snippets.

View brinnaebent's full-sized avatar

RunsData brinnaebent

View GitHub Profile
# Set sizes
plt.figure(figsize=(10,10))
plt.rcParams.update({'font.size': 20})
# Plot histogram
plt.hist(df['Glucose'])
# Labels
plt.xlabel('Glucose')
plt.ylabel('Count')
# Set sizes
plt.figure(figsize=(25,5))
plt.rcParams.update({'font.size': 20})
# Same plot as before
plt.plot(df['DateTime'], df['Glucose'], '.')
# Plot smoothed data
plt.plot(filtered, filteres[:,1], 'r')
filteres = lowess(df['Glucose'], df['DateTime'], is_sorted=True, frac=0.015, it=0) #0.025
filtered = pd.to_datetime(filteres[:,0], format='%Y-%m-%dT%H:%M:%S')
# Import lowess from the statsmodels library
from statsmodels.nonparametric.smoothers_lowess import lowess
# Calculate the mean and standard deviation of glucose. We will draw 3 lines on the plot: The mean, 1 standard deviation above the mean, and 1 standard deviation below the mean.
glucose_mean = np.mean(df['Glucose'])
up = np.mean(df['Glucose']) + np.std(df['Glucose'])
dw = np.mean(df['Glucose']) - np.std(df['Glucose'])
# Same plot as above
plt.figure(figsize=(25,5))
plt.rcParams.update({'font.size': 20})
plt.plot(df['DateTime'], df['Glucose'], '.', color = '#1f77b4')
# Designate a figure size and font size
plt.figure(figsize=(25,5))
plt.rcParams.update({'font.size': 20})
# Plot
plt.plot(df['DateTime'], df['Glucose'], '.', color = '#1f77b4')
df.describe()
df = df.reset_index(drop=True)
# We will use pd.to_datetime() to convert the Time column to a datetime object. We need to tell Python what the current format is.
df['DateTime'] = pd.to_datetime(df['DateTime'], format='%Y-%m-%dT%H:%M:%S')
# I would also like to make a new column, "Day", with just the Day of the DateTime column.
df['Day'] = df['DateTime'].dt.date