@@ -201,42 +201,6 @@ from present information back to past information. This allows the rolling windo
201
201
202
202
df
203
203
204
- .. _window.reverse_rolling_window :
205
-
206
- Reverse rolling window
207
- ~~~~~~~~~~~~~~~~~~~~~~
208
-
209
- Get the window of a rolling function to look forward.
210
-
211
- We can achieve this by using slicing in python by applying rolling aggregation and then flipping the result
212
- as shown in example below:
213
-
214
- .. ipython :: python
215
-
216
- df = pd.DataFrame(
217
- data = [
218
- [pd.Timestamp(" 2018-01-01 00:00:00" ), 100 ],
219
- [pd.Timestamp(" 2018-01-01 00:00:01" ), 101 ],
220
- [pd.Timestamp(" 2018-01-01 00:00:03" ), 103 ],
221
- [pd.Timestamp(" 2018-01-01 00:00:04" ), 111 ],
222
- ],
223
- columns = [" time" , " value" ],
224
- ).set_index(" time" )
225
- df
226
-
227
- reversed_df = df[::- 1 ].rolling(" 2s" ).sum()[::- 1 ]
228
- reversed_df
229
-
230
- Or we can also do it using :meth: `api.indexers.FixedForwardWindowIndexer ` which basically creates window boundaries
231
- for fixed-length windows that include the current row.
232
-
233
- .. ipython :: python
234
-
235
- indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size = 2 )
236
-
237
- reversed_df = df.rolling(window = indexer, min_periods = 1 ).sum()
238
- reversed_df
239
-
240
204
241
205
.. _window.custom_rolling_window :
242
206
@@ -312,12 +276,16 @@ rolling operations over a non-fixed offset like a ``BusinessDay``.
312
276
df
313
277
df.rolling(indexer).sum()
314
278
315
- For some problems knowledge of the future is available for analysis. For example, this occurs when
316
- each data point is a full time series read from an experiment, and the task is to extract underlying
317
- conditions. In these cases it can be useful to perform forward-looking rolling window computations.
318
- :func: `FixedForwardWindowIndexer <pandas.api.indexers.FixedForwardWindowIndexer> ` class is available for this purpose.
319
- This :func: `BaseIndexer <pandas.api.indexers.BaseIndexer> ` subclass implements a closed fixed-width
320
- forward-looking rolling window, and we can use it as follows:
279
+
280
+ .. _window.reverse_rolling_window :
281
+
282
+ Reverse rolling window
283
+ ~~~~~~~~~~~~~~~~~~~~~~
284
+
285
+ Get the window of a rolling function to look forward.
286
+
287
+ We can achieve this by using slicing in python by applying rolling aggregation and then flipping the result
288
+ as shown in example below:
321
289
322
290
.. ipython :: python
323
291
@@ -332,10 +300,18 @@ forward-looking rolling window, and we can use it as follows:
332
300
).set_index(" time" )
333
301
df
334
302
303
+ reversed_df = df[::- 1 ].rolling(" 2s" ).sum()[::- 1 ]
304
+ reversed_df
305
+
306
+ Or we can also do it using :meth: `api.indexers.FixedForwardWindowIndexer ` which basically creates window boundaries
307
+ for fixed-length windows that include the current row.
308
+
309
+ .. ipython :: python
310
+
335
311
indexer = pd.api.indexers.FixedForwardWindowIndexer(window_size = 2 )
336
312
337
- df_out = df.rolling(window = indexer, min_periods = 1 ).sum()
338
- df_out
313
+ reversed_df = df.rolling(window = indexer, min_periods = 1 ).sum()
314
+ reversed_df
339
315
340
316
341
317
.. _window.rolling_apply :
0 commit comments