Skip to content

Instantly share code, notes, and snippets.

@anatol-grabowski
Last active April 7, 2018 08:45
Show Gist options
  • Save anatol-grabowski/c075f74b11a9a42b2c983d323bb83efa to your computer and use it in GitHub Desktop.
Save anatol-grabowski/c075f74b11a9a42b2c983d323bb83efa to your computer and use it in GitHub Desktop.
np.random.seed(123)
num_vals = 27
index = pd.DatetimeIndex(start='jan 2 2018', periods=num_vals, freq='1D', name='date')
data = np.random.randn(num_vals)
dff = pd.DataFrame(data, index=index, columns=['val'])
dff.loc[:, 'weekday'] = dff.index.weekday
dff.loc[:, 'weekstart'] = dff.index - dff.index.weekday.astype('timedelta64[D]')
piv = dff.pivot(columns='weekday', values='val', index='weekstart')
piv.rename(inplace=True, columns={0: 'Mon', 1: 'Tue', 2: 'Wed', 3: 'Thu', 4: 'Fri', 5: 'Sat', 6: 'Sun'})
piv.dropna(inplace=True)
plt.boxplot(piv.T);
piv.T
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment