In [1]:
%matplotlib inline

import matplotlib.pyplot as plt


/Users/BadWizard/anaconda3/envs/py35/lib/python3.5/site-packages/matplotlib/style/core.py:197: UserWarning: In /Users/BadWizard/.matplotlib/stylelib/my_custom_style.mplstyle: axes.color_cycle is deprecated and replaced with axes.prop_cycle; please use the latter.
  warnings.warn(message)

In [2]:
plt.style.use('seaborn')

In [3]:
from jupyterworkflow.data import get_fremont_data

In [4]:
data = get_fremont_data()

In [5]:
data.index


Out[5]:
DatetimeIndex(['2012-10-03 00:00:00', '2012-10-03 01:00:00',
               '2012-10-03 02:00:00', '2012-10-03 03:00:00',
               '2012-10-03 04:00:00', '2012-10-03 05:00:00',
               '2012-10-03 06:00:00', '2012-10-03 07:00:00',
               '2012-10-03 08:00:00', '2012-10-03 09:00:00',
               ...
               '2017-07-31 14:00:00', '2017-07-31 15:00:00',
               '2017-07-31 16:00:00', '2017-07-31 17:00:00',
               '2017-07-31 18:00:00', '2017-07-31 19:00:00',
               '2017-07-31 20:00:00', '2017-07-31 21:00:00',
               '2017-07-31 22:00:00', '2017-07-31 23:00:00'],
              dtype='datetime64[ns]', name='Date', length=42312, freq=None)

In [6]:
data.plot()


Out[6]:
<matplotlib.axes._subplots.AxesSubplot at 0x10e806ba8>

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


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

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

In [9]:
data['Total'] = data['West'] + data['East']

ax = data.resample('D').sum().rolling(365).sum().plot()
ax.set_ylim(0, None)


Out[9]:
(0, 1059460.05)

In [10]:
data.groupby(data.index.time).mean().plot()


Out[10]:
<matplotlib.axes._subplots.AxesSubplot at 0x10fee64a8>

In [11]:
data.head()


Out[11]:
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 [12]:
pivoted = data.pivot_table('Total', index = data.index.time, columns=data.index.date)

In [13]:
pivoted.iloc[:24, :5]


Out[13]:
2012-10-03 2012-10-04 2012-10-05 2012-10-06 2012-10-07
00:00:00 13.0 18.0 11.0 15.0 11.0
01:00:00 10.0 3.0 8.0 15.0 17.0
02:00:00 2.0 9.0 7.0 9.0 3.0
03:00:00 5.0 3.0 4.0 3.0 6.0
04:00:00 7.0 8.0 9.0 5.0 3.0
05:00:00 31.0 26.0 25.0 5.0 9.0
06:00:00 155.0 142.0 105.0 27.0 17.0
07:00:00 352.0 319.0 319.0 33.0 26.0
08:00:00 437.0 418.0 370.0 105.0 69.0
09:00:00 276.0 241.0 212.0 114.0 103.0
10:00:00 118.0 120.0 119.0 115.0 108.0
11:00:00 42.0 108.0 104.0 124.0 165.0
12:00:00 76.0 104.0 101.0 164.0 191.0
13:00:00 90.0 126.0 112.0 177.0 228.0
14:00:00 128.0 119.0 125.0 203.0 241.0
15:00:00 164.0 147.0 164.0 211.0 231.0
16:00:00 315.0 275.0 310.0 183.0 225.0
17:00:00 583.0 507.0 434.0 180.0 191.0
18:00:00 380.0 378.0 316.0 96.0 113.0
19:00:00 128.0 164.0 115.0 78.0 49.0
20:00:00 80.0 83.0 68.0 43.0 55.0
21:00:00 63.0 70.0 42.0 33.0 47.0
22:00:00 49.0 46.0 36.0 34.0 18.0
23:00:00 17.0 41.0 32.0 34.0 16.0

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


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

In [15]:
pivoted.index


Out[15]:
Index([00:00:00, 01:00:00, 02:00:00, 03:00:00, 04:00:00, 05:00:00, 06:00:00,
       07:00:00, 08:00:00, 09:00:00, 10:00:00, 11:00:00, 12:00:00, 13:00:00,
       14:00:00, 15:00:00, 16:00:00, 17:00:00, 18:00:00, 19:00:00, 20:00:00,
       21:00:00, 22:00:00, 23:00:00],
      dtype='object')

In [16]:
get_fremont_data()


Out[16]:
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
2012-10-03 05:00:00 21.0 10.0 31.0
2012-10-03 06:00:00 105.0 50.0 155.0
2012-10-03 07:00:00 257.0 95.0 352.0
2012-10-03 08:00:00 291.0 146.0 437.0
2012-10-03 09:00:00 172.0 104.0 276.0
2012-10-03 10:00:00 72.0 46.0 118.0
2012-10-03 11:00:00 10.0 32.0 42.0
2012-10-03 12:00:00 35.0 41.0 76.0
2012-10-03 13:00:00 42.0 48.0 90.0
2012-10-03 14:00:00 77.0 51.0 128.0
2012-10-03 15:00:00 72.0 92.0 164.0
2012-10-03 16:00:00 133.0 182.0 315.0
2012-10-03 17:00:00 192.0 391.0 583.0
2012-10-03 18:00:00 122.0 258.0 380.0
2012-10-03 19:00:00 59.0 69.0 128.0
2012-10-03 20:00:00 29.0 51.0 80.0
2012-10-03 21:00:00 25.0 38.0 63.0
2012-10-03 22:00:00 24.0 25.0 49.0
2012-10-03 23:00:00 5.0 12.0 17.0
2012-10-04 00:00:00 7.0 11.0 18.0
2012-10-04 01:00:00 3.0 0.0 3.0
2012-10-04 02:00:00 3.0 6.0 9.0
2012-10-04 03:00:00 0.0 3.0 3.0
2012-10-04 04:00:00 7.0 1.0 8.0
2012-10-04 05:00:00 15.0 11.0 26.0
... ... ... ...
2017-07-30 18:00:00 60.0 92.0 152.0
2017-07-30 19:00:00 46.0 70.0 116.0
2017-07-30 20:00:00 49.0 47.0 96.0
2017-07-30 21:00:00 18.0 34.0 52.0
2017-07-30 22:00:00 21.0 13.0 34.0
2017-07-30 23:00:00 12.0 12.0 24.0
2017-07-31 00:00:00 2.0 3.0 5.0
2017-07-31 01:00:00 5.0 2.0 7.0
2017-07-31 02:00:00 1.0 0.0 1.0
2017-07-31 03:00:00 2.0 0.0 2.0
2017-07-31 04:00:00 6.0 5.0 11.0
2017-07-31 05:00:00 32.0 20.0 52.0
2017-07-31 06:00:00 99.0 67.0 166.0
2017-07-31 07:00:00 269.0 223.0 492.0
2017-07-31 08:00:00 348.0 312.0 660.0
2017-07-31 09:00:00 172.0 192.0 364.0
2017-07-31 10:00:00 73.0 75.0 148.0
2017-07-31 11:00:00 58.0 61.0 119.0
2017-07-31 12:00:00 56.0 51.0 107.0
2017-07-31 13:00:00 44.0 63.0 107.0
2017-07-31 14:00:00 68.0 77.0 145.0
2017-07-31 15:00:00 74.0 93.0 167.0
2017-07-31 16:00:00 104.0 261.0 365.0
2017-07-31 17:00:00 199.0 641.0 840.0
2017-07-31 18:00:00 162.0 393.0 555.0
2017-07-31 19:00:00 88.0 182.0 270.0
2017-07-31 20:00:00 56.0 98.0 154.0
2017-07-31 21:00:00 53.0 53.0 106.0
2017-07-31 22:00:00 13.0 28.0 41.0
2017-07-31 23:00:00 12.0 26.0 38.0

42312 rows × 3 columns


In [ ]: