In [1]:
URL = 'https://data.seattle.gov/api/views/65db-xm6k/rows.csv?accessType=DOWNLOAD'

In [2]:
from urllib.request import urlretrieve
urlretrieve(URL, 'Fremont.csv')


Out[2]:
('Fremont.csv', <http.client.HTTPMessage at 0x10fe9d3c8>)

In [3]:
!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

In [4]:
import pandas as pd
df = pd.read_csv('Fremont.csv', index_col='Date', parse_dates=True)
df.head()


Out[4]:
Fremont Bridge West Sidewalk Fremont Bridge East Sidewalk
Date
2012-10-03 00:00:00 4.0 9.0
2012-10-03 01:00:00 4.0 6.0
2012-10-03 02:00:00 1.0 1.0
2012-10-03 03:00:00 2.0 3.0
2012-10-03 04:00:00 6.0 1.0

In [5]:
%matplotlib inline

In [6]:
df.info()


<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 38640 entries, 2012-10-03 00:00:00 to 2017-02-28 23:00:00
Data columns (total 2 columns):
Fremont Bridge West Sidewalk    38633 non-null float64
Fremont Bridge East Sidewalk    38633 non-null float64
dtypes: float64(2)
memory usage: 905.6 KB

In [7]:
df.plot()


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

In [8]:
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')

df.columns = ['West', 'East']

df.resample('W').sum().plot();



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

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



In [10]:
#trend in individual days
df.groupby(df.index.time).mean().plot();



In [11]:
pivoted = df.pivot_table('Total', index=df.index.time, columns=df.index.date)
pivoted.iloc[:5, :5]


Out[11]:
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

In [12]:
#line for each days of the year
pivoted.plot(legend=False, alpha=0.01);



In [ ]: