Pandas api indexers class VariableOffsetWindowIndexer in Python
The Pandas api indexers class VariableOffsetWindowIndexer used to calculate window boundaries based on a non-fixed offset such as a BusinessDay.
Syntax
 1 class pandas.api.indexers.VariableOffsetWindowIndexer(index_array = None,
 2  window_size = 0, index = None, offset = None, **kwargs)
VariableOffsetWindowIndexer class
 1 import pandas as pd
 2 from pandas.api.indexers import VariableOffsetWindowIndexer
 3         
 4 df = pd.DataFrame(range(5), index = pd.date_range('2022', periods = 5))
 5 offset = pd.offsets.BDay(1)
 6 
 7 indexer = VariableOffsetWindowIndexer(index = df.index, offset = offset)
 8 res = df.rolling(indexer).sum()
 9 
 10 print('The sum of indexer :')
 11 print(res)
In the above example, a VariableOffsetWindowIndexer object is created by passing an index and offset. A sum() function is called of rolling object. The result is assign to the variable that will be printed on console.
Output
 1 The sum of indexer :
 2               0
 3 2022-01-01  0.0
 4 2022-01-02  1.0
 5 2022-01-03  3.0
 6 2022-01-04  3.0
 7 2022-01-05  4.0
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us