What is the intuition behind win_type argument in rolling function of Pandas?

Question:

The following code is from Python DataScience Handbook (line 42)

daily.rolling(50, center=True,
              win_type='gaussian').sum(std=10).plot(style=[':', '--', '-']);

While I understand why we need rolling, I am unable to understand why are we using win_type.

Could you people please help in clearing this doubt? I’ve searched the Pandas documentation but unfortunately, they don’t have the required explanation.

Asked By: kusur

||

Answers:

I am far from being an expert on the topic, but from my understanding the win_type argument is derived from signal processing concepts:
https://en.wikipedia.org/wiki/Window_function

In signal processing, a window function (also known as an apodization
function or tapering function[1]) is a mathematical function that is
zero-valued outside of some chosen interval. For instance, a function
that is constant inside the interval and zero elsewhere is called a
rectangular window, which describes the shape of its graphical
representation. When another function or waveform/data-sequence is
multiplied by a window function, the product is also zero-valued
outside the interval: all that is left is the part where they overlap,
the “view through the window”.

Answered By: Dana Averbuch

The ‘win_type=’ argument allows you to specify a windowing function that ‘rolls’ over your data. In your example a Gaussian window is used with standard deviation width of 10 samples, and extends to 2.5 standard deviations on either side (total size of 50 samples). If you don’t specify ‘win_type=’ you’ll get a rectangular window.

Note that if ‘win_type=’ is specified a ‘window’ subclass returned, otherwise a ‘rolling’ subclass is returned.

https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.rolling.html

Answered By: Michael
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.