In [15]:
import os
from urllib.request import urlretrieve
import pandas as pd
URL = 'https://data.seattle.gov/api/views/65db-xm6k/rows.csv?accessType=DOWNLOAD'
def get_fremont_data(filename='Fremont.csv',url=URL, force_download=False):
if force_download or not os.path.exists(filename):
urlretrieve(URL, filename)
data = pd.read_csv('Fremont.csv', index_col='Date', parse_dates=True)
data.columns = ['West','East']
data['Total'] = data['West'] + data['East']
return data
In [16]:
data = get_fremont_data()
In [17]:
data.head()
Out[17]:
In [18]:
%matplotlib inline
data.plot()
data.resample('W').sum().plot()
Out[18]:
In [19]:
import seaborn as sns
sns.set()
data.resample('W').sum().plot()
Out[19]:
In [20]:
ax = data.resample('D').rolling(365).sum().plot()
ax.set_ylim(0,None);
In [21]:
data.groupby(data.index.time).mean().plot()
Out[21]:
In [22]:
pivoted = data.pivot_table('Total',index=data.index.time,columns=data.index.date)
pivoted.iloc[:5, :5]
Out[22]:
In [23]:
pivoted.plot(legend=False,alpha=0.01)
Out[23]: