File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -143,20 +143,34 @@ name of the dimension as a key (e.g. ``y``) and the window size as the value
143
143
144
144
arr.rolling(y = 3 )
145
145
146
- The label position and minimum number of periods in the rolling window are
147
- controlled by the `` center `` and `` min_periods `` arguments :
146
+ Aggregation and summary methods can be applied directly to the `` Rolling ``
147
+ object :
148
148
149
149
.. ipython :: python
150
150
151
- arr.rolling(y = 3 , min_periods = 2 , center = True )
151
+ r = arr.rolling(y = 3 )
152
+ r.reduce(np.std)
153
+ r.mean()
152
154
153
- Aggregation and summary methods can be applied directly to the ``Rolling `` object:
155
+ Aggregation results are at the end of each window by default, but can be
156
+ centered by passing ``center=True `` when constructing the ``Rolling `` object:
154
157
155
158
.. ipython :: python
156
159
157
- r = arr.rolling(y = 3 )
160
+ r = arr.rolling(y = 3 , center = True )
161
+ r.mean()
162
+
163
+ As can be seen above, aggregations of windows which overlap the border of the
164
+ array produce ``nan``s. Setting ``min_periods `` in the call to ``rolling ``
165
+ changes the minimum number of observations within the window required to have
166
+ a value when aggregating:
167
+
168
+ .. ipython :: python
169
+
170
+ r = arr.rolling(y = 3 , min_periods = 2 )
171
+ r.mean()
172
+ r = arr.rolling(y = 3 , center = True , min_periods = 2 )
158
173
r.mean()
159
- r.reduce(np.std)
160
174
161
175
Note that rolling window aggregations are faster when bottleneck _ is installed.
162
176
You can’t perform that action at this time.
0 commit comments