datatable.cummax()

Added in version 1.1.0

For each column from cols calculate cumulative maximum. In the presence of by(), the cumulative maximum is computed within each group.

Parameters

cols
FExpr

Input data for cumulative maximum calculation.

reverse
bool

If False, computation is done from top to bottom. If True, it is done from bottom to top.

return
FExpr

f-expression that converts input columns into the columns filled with the respective cumulative maximums.

except
TypeError

The exception is raised when one of the columns from cols has a non-numeric type.

Examples

Create a sample datatable frame:

from datatable import dt, f, by DT = dt.Frame({"A": [2, None, 5, -1, 0], "B": [None, None, None, None, None], "C": [5.4, 3, 2.2, 4.323, 3], "D": ['a', 'a', 'b', 'b', 'b']})
ABCD
int32voidfloat64str32
02NA5.4a
1NANA3a
25NA2.2b
3-1NA4.323b
40NA3b

Calculate the cumulative maximum in a single column:

DT[:, dt.cummax(f.A)]
A
int32
02
12
25
35
45

Calculate the cumulative maximum from bottom to top:

DT[:, dt.cummax(f.A, reverse=True)]
A
int32
05
15
25
30
40

Calculate the cumulative maximum in multiple columns:

DT[:, dt.cummax(f[:-1])]
ABC
int32voidfloat64
02NA5.4
12NA5.4
25NA5.4
35NA5.4
45NA5.4

For a grouped frame calculate the cumulative maximum within each group:

DT[:, dt.cummax(f[:]), by('D')]
DABC
str32int32voidfloat64
0a2NA5.4
1a2NA5.4
2b5NA2.2
3b5NA4.323
4b5NA4.323