Groupby.cummax
Obtain the cummulative max per groups for each column
Parameters: None
Return: DataFrame
Examples
Obtain the cumulative max of a column for each groups, group by one column
Node
const dfd = require("danfojs-node")
let data ={A: ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
B: ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
C: [1,3,2,4,5,2,6,7],
D: [3,2,4,1,5,6,7,8]
}
let df = new dfd.DataFrame(data)
let grp = df.groupby(["A"])
grp.col(["C"]).cumMax().head().print()
grp.col(["C"]).cumMax().tail().print()
Shape: (5,2)
╔═══╤═══════════════════╤═══════════════════╗
║ │ A │ C_cummax ║
╟───┼──────────────── ───┼───────────────────╢
║ 0 │ foo │ 1 ║
╟───┼───────────────────┼───────────────────╢
║ 1 │ foo │ 2 ║
╟───┼───────────────────┼───────────────────╢
║ 2 │ foo │ 5 ║
╟───┼───────────────────┼───────────────────╢
║ 3 │ foo │ 6 ║
╟───┼───────────────────┼───────────────────╢
║ 4 │ foo │ 7 ║
╚═══╧═══════════════════╧═══════════════════╝
Shape: (5,2)
╔═══╤═══════════════════╤═══════════════════╗
║ │ A │ C_cummax ║
╟───┼───────────────────┼───────────────────╢
║ 3 │ foo │ 6 ║
╟───┼───────────────────┼───────────────────╢
║ 4 │ foo │ 7 ║
╟───┼───────────────────┼───────────────────╢
║ 5 │ bar │ 3 ║
╟───┼───────────────────┼───────────────────╢
║ 6 │ bar │ 4 ║
╟───┼───────────────────┼───────────────────╢
║ 7 │ bar │ 4 ║
╚═══╧═══════════════════╧═══════════════════╝
Obtain the cumsum for two columns for each group, group by one column
Node
const dfd = require("danfojs-node")
let data ={A: ['foo', 'bar', 'foo', 'bar',
'foo', 'bar', 'foo', 'foo'],
B: ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
C: [1,3,2,4,5,2,6,7],
D: [3,2,4,1,5,6,7,8]
}
let df = new dfd.DataFrame(data)
let grp = df.groupby(["A"])
grp.col(["C","D"]).cumMax().head().print()
grp.col(["C","D"]).cumMax().tail().print()
Shape: (5,3)
╔═══╤═══════════════════╤══════════════════ ═╤═══════════════════╗
║ │ A │ C_cummax │ D_cummax ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 0 │ foo │ 1 │ 3 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢
║ 1 │ foo │ 2 │ 4 ║
╟───┼───────────────────┼─── ────────────────┼───────────────────╢
║ 2 │ foo │ 5 │ 5 ║
╟───┼───────────────────┼───────────────────┼───────────────────╢