pandas.api.indexers.VariableOffsetWindowIndexer#
- classpandas.api.indexers.VariableOffsetWindowIndexer(index_array=None, window_size=0, index=None, offset=None, **kwargs)[source] #
Calculate window boundaries based on a non-fixed offset such as a BusinessDay.
- Parameters:
- index_arraynp.ndarray, default 0
Array-like structure specifying the indices for data points. This parameter is currently not used.
- window_sizeint, optional, default 0
Specifies the number of data points in each window. This parameter is currently not used.
- indexDatetimeIndex, optional
DatetimeIndex
of the labels of each observation.- offsetBaseOffset, optional
DateOffset
representing the size of the window.- **kwargs
Additional keyword arguments passed to the parent class
BaseIndexer
.
See also
api.indexers.BaseIndexer
Base class for all indexers.
DataFrame.rolling
Rolling window calculations on DataFrames.
offsets
Module providing various time offset classes.
Examples
>>> frompandas.api.indexersimport VariableOffsetWindowIndexer >>> df = pd.DataFrame(range(10), index=pd.date_range("2020", periods=10)) >>> offset = pd.offsets.BDay(1) >>> indexer = VariableOffsetWindowIndexer(index=df.index, offset=offset) >>> df 0 2020年01月01日 0 2020年01月02日 1 2020年01月03日 2 2020年01月04日 3 2020年01月05日 4 2020年01月06日 5 2020年01月07日 6 2020年01月08日 7 2020年01月09日 8 2020年01月10日 9 >>> df.rolling(indexer).sum() 0 2020年01月01日 0.0 2020年01月02日 1.0 2020年01月03日 2.0 2020年01月04日 3.0 2020年01月05日 7.0 2020年01月06日 12.0 2020年01月07日 6.0 2020年01月08日 7.0 2020年01月09日 8.0 2020年01月10日 9.0
Methods
get_window_bounds
([num_values, min_periods, ...])Computes the bounds of a window.