Windows Function

tools.window.apply_cum(series, cum_func=<function <lambda>>, judge_func=<function <lambda>>, init_value=0)

Apply Cumulative Function on Series or list

Parameters:
  • series (list or series) –
  • cum_func (cumulative function with two parameters) –
  • judge_func (judge function which return value is True or False for reset cumulative value) –
  • init_value (reset value if judge function result is True) –
Returns:

Return type:

DataFrame with three columns(cum_value, index_first, index_last)

Example

>>> import numpy as np
>>> from tidyframe import apply_cum
>>> series = np.random.randint(1, 6, 10)
>>> cum_func = lambda x, y: x * y
>>> judge_func = lambda x: x > 10
>>> apply_cum(series, cum_func, init_value=1)
cum_value  index_first  index_last
0          4         True       False
1          4        False       False
2         20        False       False
3         20        False       False
4        100        False       False
5        200        False       False
6        200        False       False
7        600        False       False
8        600        False       False
9       2400        False       False