from Jake Vanderplas http://jakevdp.github.io/blog/2017/03/03/reproducible-data-analysis-in-jupyter/
This walks through a whole series, loading some data for analysis from the Fremont bridge bike data in Seattle, packaging some functionality into a python package (fremont) and doing some basic unit testing with the pytest package. To run the tests, run
'python -m pytest fremont'
from its parent directory. This will find all test functions and run them.
In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn')
In [2]:
#this imports a small python package for downloading the fremont bike data
#into a dataframe if it is not already downloaded
from fremont.data import get_fremont_data
In [3]:
data = get_fremont_data()
data.head()
Out[3]:
In [4]:
data.resample('W').sum().plot()
Out[4]:
In [5]:
#resample to daily with rolling sum (Note TWO sum() functions)
ax=data.resample('D').sum().rolling(365).sum().plot()
ax.set_ylim(0, None)
Out[5]:
In [6]:
data.groupby(data.index.time).mean().plot()
Out[6]:
In [7]:
pivoted = data.pivot_table('Total', index = data.index.time, columns = data.index.date)
pivoted.iloc[:5,:5]
Out[7]:
In [8]:
pivoted.plot(legend=False, alpha=0.01)
Out[8]: