pandas.api.indexers.BaseIndexer #

pandas.api.indexers类 BaseIndexer ( index_array = None , window_size = 0 , ** kwargs ) [来源] #

窗口边界计算的基类。

例子

>>> from pandas.api.indexers import BaseIndexer
>>> class CustomIndexer(BaseIndexer):
...     def get_window_bounds(self, num_values, min_periods, center, closed, step):
...         start = np.empty(num_values, dtype=np.int64)
...         end = np.empty(num_values, dtype=np.int64)
...         for i in range(num_values):
...             start[i] = i
...             end[i] = i + self.window_size
...         return start, end
>>> df = pd.DataFrame({"values": range(5)})
>>> indexer = CustomIndexer(window_size=2)
>>> df.rolling(indexer).sum()
    values
0   1.0
1   3.0
2   5.0
3   7.0
4   4.0

方法

get_window_bounds([num_values, min_periods, ...])

计算窗口的边界。