Handling date objects in Python
Time series is data that is sampled at certain intervals over time, for example, recording the speed of a car every second. Given such data, we can easily estimate either the distance traveled (by summing the observations and dividing the sum by 3,600) or acceleration of the car (by calculating the differences between two consecutive observations). Managing time series data with pandas
is straightforward.
Getting ready
To execute this recipe, you will need pandas
, NumPy
, and Matplotlib
. No other prerequisites are necessary.
How to do it…
From the web archive, we cleaned up and transformed two datasets: water flow for the American River (http://www.theamericanriver.com) and for the Columbia River (http://www.ecy.wa.gov/programs/wr/cwp/cwpfactmap.html). With pandas
, it is extremely easy to read the time series dataset (the ts_handlingData.py
file):
import numpy as np import pandas as pd import pandas.tseries.offsets as ofst # files we'll be working with files =...