Skip to content

Commit c3538c5

Browse files
committed
DOC: rolling window examples #2477
1 parent 806da06 commit c3538c5

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

doc/source/computation.rst

+53-1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ otherwise they can be found in :mod:`pandas.stats.moments`.
212212
``rolling_cov``, Unbiased covariance (binary)
213213
``rolling_corr``, Correlation (binary)
214214
``rolling_corr_pairwise``, Pairwise correlation of DataFrame columns
215+
``rolling_window``, Moving window function
215216

216217
Generally these methods all have the same interface. The binary operators
217218
(e.g. ``rolling_corr``) take two Series or DataFrames. Otherwise, they all
@@ -265,6 +266,58 @@ compute the mean absolute deviation on a rolling basis:
265266
@savefig rolling_apply_ex.png width=4.5in
266267
rolling_apply(ts, 60, mad).plot(style='k')
267268
269+
The ``rolling_window`` function performs a generic rolling window computation
270+
on the input data. The weights used in the window are specified by the ``win_type``
271+
keyword. The list of recognized types are:
272+
273+
- ``boxcar``
274+
- ``triang``
275+
- ``blackman``
276+
- ``hamming``
277+
- ``bartlett``
278+
- ``parzen``
279+
- ``bohman``
280+
- ``blackmanharris``
281+
- ``nuttall``
282+
- ``barthann``
283+
- ``kaiser`` (needs beta)
284+
- ``gaussian`` (needs std)
285+
- ``general_gaussian`` (needs power, width)
286+
- ``slepian`` (needs width).
287+
288+
.. ipython:: python
289+
290+
ser = Series(randn(10), index=date_range('1/1/2000', periods=10))
291+
292+
rolling_window(ser, 5, 'triang')
293+
294+
Note that the ``boxcar`` window is equivalent to ``rolling_mean``:
295+
296+
.. ipython:: python
297+
298+
rolling_window(ser, 5, 'boxcar')
299+
300+
rolling_mean(ser, 5)
301+
302+
For some windowing functions, additional parameters must be specified:
303+
304+
.. ipython:: python
305+
306+
rolling_window(ser, 5, 'gaussian', std=0.1)
307+
308+
By default the labels are set to the right edge of the window, but a
309+
``center`` keyword is available so the labels can be set at the center.
310+
This keyword is available in other rolling functions as well.
311+
312+
.. ipython:: python
313+
314+
rolling_window(ser, 5, 'boxcar')
315+
316+
rolling_window(ser, 5, 'boxcar', center=True)
317+
318+
rolling_mean(ser, 5, center=True)
319+
320+
268321
.. _stats.moments.binary:
269322

270323
Binary rolling moments
@@ -634,4 +687,3 @@ Result fields and tests
634687

635688
We'll leave it to the user to explore the docstrings and source, especially as
636689
we'll be moving this code into statsmodels in the near future.
637-

pandas/stats/moments.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -580,14 +580,14 @@ def rolling_window(arg, window=None, win_type=None, min_periods=None,
580580
freq=None, center=False, mean=True, time_rule=None,
581581
axis=0, **kwargs):
582582
"""
583-
Applies a centered moving window of type ``window_type`` and size ``window``
583+
Applies a moving window of type ``window_type`` and size ``window``
584584
on the data.
585585
586586
Parameters
587587
----------
588588
arg : Series, DataFrame
589589
window : int or ndarray
590-
Filtering window specification. If the window is an integer, then it is
590+
Weighting window specification. If the window is an integer, then it is
591591
treated as the window length and win_type is required
592592
win_type : str, default None
593593
Window type (see Notes)

0 commit comments

Comments
 (0)