Header

Import packages

$sin(x)$


In [36]:
import sys
import numpy as np

In [47]:
from jupyterworkflow import data

In [48]:
data = get_fremont_data()
data.head()


Out[48]:
West East Total
Date
2012-10-03 00:00:00 4.0 9.0 13.0
2012-10-03 01:00:00 4.0 6.0 10.0
2012-10-03 02:00:00 1.0 1.0 2.0
2012-10-03 03:00:00 2.0 3.0 5.0
2012-10-03 04:00:00 6.0 1.0 7.0

In [4]:
!head Fremont.csv


Date,Fremont Bridge West Sidewalk,Fremont Bridge East Sidewalk
10/03/2012 12:00:00 AM,4,9
10/03/2012 01:00:00 AM,4,6
10/03/2012 02:00:00 AM,1,1
10/03/2012 03:00:00 AM,2,3
10/03/2012 04:00:00 AM,6,1
10/03/2012 05:00:00 AM,21,10
10/03/2012 06:00:00 AM,105,50
10/03/2012 07:00:00 AM,257,95
10/03/2012 08:00:00 AM,291,146

Make some plots


In [7]:
%matplotlib inline
data.sum().plot()


Out[7]:
<matplotlib.axes._subplots.AxesSubplot at 0x11373d518>

In [8]:
data.resample('W').sum().plot();



In [9]:
import matplotlib.pyplot as plt
plt.style.use('bmh')
data.resample('W').sum().plot(figsize=(12,4))
plt.gca().legend(bbox_to_anchor=(1,1), loc='upper left')


Out[9]:
<matplotlib.legend.Legend at 0x10988ab00>

In [10]:
ax = data.resample('D').sum().rolling(365).sum().plot()
ax.set_ylim(0,None)


Out[10]:
(0, 1058559.2)

In [11]:
data.groupby(data.index.time).mean().plot(figsize=(12,4))


Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x11375e0b8>

In [12]:
pivoted = data.pivot_table('Total',index=data.index.time,columns=data.index.date)
pivoted.head()


Out[12]:
2012-10-03 2012-10-04 2012-10-05 2012-10-06 2012-10-07 2012-10-08 2012-10-09 2012-10-10 2012-10-11 2012-10-12 ... 2017-03-22 2017-03-23 2017-03-24 2017-03-25 2017-03-26 2017-03-27 2017-03-28 2017-03-29 2017-03-30 2017-03-31
00:00:00 13.0 18.0 11.0 15.0 11.0 9.0 12.0 15.0 21.0 17.0 ... 7.0 6.0 10.0 13.0 11.0 2.0 6.0 6.0 6.0 6.0
01:00:00 10.0 3.0 8.0 15.0 17.0 4.0 3.0 3.0 10.0 13.0 ... 2.0 4.0 3.0 5.0 6.0 3.0 2.0 4.0 0.0 2.0
02:00:00 2.0 9.0 7.0 9.0 3.0 5.0 4.0 3.0 13.0 5.0 ... 1.0 0.0 4.0 3.0 3.0 0.0 0.0 1.0 3.0 1.0
03:00:00 5.0 3.0 4.0 3.0 6.0 5.0 8.0 4.0 2.0 7.0 ... 0.0 2.0 1.0 2.0 0.0 2.0 2.0 1.0 1.0 1.0
04:00:00 7.0 8.0 9.0 5.0 3.0 5.0 9.0 5.0 12.0 5.0 ... 7.0 6.0 3.0 2.0 1.0 4.0 5.0 4.0 9.0 6.0

5 rows × 1641 columns


In [13]:
pivoted.plot(legend=False)


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x11627ae80>

In [14]:
pivoted.plot(legend=False, alpha=0.01,figsize=(12,4))


Out[14]:
<matplotlib.axes._subplots.AxesSubplot at 0x118bc9ba8>

In [ ]: