staircase.StairsSlicer.apply#

StairsSlicer.apply(func, *args, **kwargs)#

Applies a method to each step function slice

Parameters
funccallable

Must be a function which takes a Stairs instance as first parameter

args, kwargstuple and dict

Optional positional and keyword arguments to pass to func.

Returns
pandas.Series

Examples

>>> df = sc.make_test_data(seed=0)
>>> sf = sc.Stairs(df, "start", "end", "value")
>>> sf.plot()
../../_images/staircase-StairsSlicer-apply-1.png
>>> def step_count_above_threshold(s, n):
...     return s.number_of_steps > n
...
>>> cuts = pd.date_range("2021", periods=12, freq="MS")
>>> sf.slice(cuts).apply(step_count_above_threshold, 120)
[2021-01-01, 2021-02-01)     True
[2021-02-01, 2021-03-01)    False
[2021-03-01, 2021-04-01)    False
[2021-04-01, 2021-05-01)    False
[2021-05-01, 2021-06-01)     True
[2021-06-01, 2021-07-01)     True
[2021-07-01, 2021-08-01)    False
[2021-08-01, 2021-09-01)     True
[2021-09-01, 2021-10-01)    False
[2021-10-01, 2021-11-01)     True
[2021-11-01, 2021-12-01)     True
dtype: bool