In [1]:
# mofiy the gitignore file
# create a function. dont download the csv file if it is exist.
In [2]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
In [3]:
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)
df = pd.read_csv('Fremont.csv', index_col='Date', parse_dates=True)
df.columns = ['West', 'East']
df['Total'] = df['West'] + df['East']
return df
In [4]:
data = get_fremont_data()
data.head()
Out[4]:
In [5]:
data.plot()
Out[5]:
In [6]:
data.resample('W').sum().plot();
In [7]:
ax = data.resample('D').sum().rolling(365).sum().plot();
ax.set_ylim(0, None);
In [8]:
#trend in individual days
data.groupby(data.index.time).mean().plot();
In [9]:
pivoted = data.pivot_table('Total', index=data.index.time, columns=data.index.date)
pivoted.iloc[:5, :5]
Out[9]:
In [10]:
#line for each days of the year
pivoted.plot(legend=False, alpha=0.01);
In [ ]: