Smoothing and transforming the observations

Smoothing data removes some of the noise from the data and makes the chart appear smooth (hence the name).

Should you do it? For presentation purposes, sure! For modeling purposes, not necessarily—check this argument by William Briggs at http://wmbriggs.com/post/195/.

Getting ready

To execute this recipe, you will need pandas, NumPy, and Matplotlib. No other prerequisites are required.

How to do it…

In this recipe, we will see how to calculate the moving averages and transform the data using a logarithmic function (the ts_smoothing.py file):

ma_transform12  = pd.rolling_mean(riverFlows, window=12)
ma_transformExp = pd.ewma(riverFlows, span=3)
log_transfrom   = riverFlows.apply(np.log)

How it works…

The .rolling_mean(...) ...

Get Practical Data Analysis Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.