danfo.Groupby.cummax() [source]
Parameters: None
Return: DataFrame
Examples
Obtain the cumulative max of a column for each groups, group by one column
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
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 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 3 │ foo │ 6 │ 7 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 4 │ foo │ 7 │ 8 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝Shape: (5,3)╔════╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ A │ C_cummax │ D_cummax ║╟────┼───────────────────┼───────────────────┼───────────────────╢║ 11 │ bar │ 4 │ 2 ║╟────┼───────────────────┼───────────────────┼───────────────────╢║ 12 │ bar │ 4 │ 6 ║╟────┼───────────────────┼───────────────────┼───────────────────╢║ 13 │ bar │ 3 │ 2 ║╟────┼───────────────────┼───────────────────┼───────────────────╢║ 14 │ bar │ 4 │ 2 ║╟────┼───────────────────┼───────────────────┼───────────────────╢║ 15 │ bar │ 4 │ 6 ║╚════╧═══════════════════╧═══════════════════╧═══════════════════╝
Obtain the cummax for a column for each group, group by two columns
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","B"])grp.col(["C"]).cummax().head().print()grp.col(["C"]).cummax().tail().print()
Shape: (5,3)╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ A │ B │ C_cummax ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 0 │ foo │ one │ 1 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 1 │ foo │ one │ 6 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 2 │ foo │ two │ 2 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 3 │ foo │ two │ 5 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 4 │ foo │ three │ 7 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝Shape: (5,3)╔═══╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ A │ B │ C_cummax ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 3 │ foo │ two │ 5 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 4 │ foo │ three │ 7 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 5 │ bar │ one │ 3 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 6 │ bar │ two │ 2 ║╟───┼───────────────────┼───────────────────┼───────────────────╢║ 7 │ bar │ three │ 4 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╝
Obtain the cummax for two columns for each group, group by two columns
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","B"])grp.col(["C","D"]).cummax().head().print()grp.col(["C","D"]).cummax().tail().print()
Shape: (5,4)╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ A │ B │ C_cummax │ D_cummax ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 0 │ foo │ one │ 1 │ 3 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 1 │ foo │ one │ 6 │ 7 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 2 │ foo │ two │ 2 │ 4 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 3 │ foo │ two │ 5 │ 5 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 4 │ foo │ three │ 7 │ 8 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝Shape: (5,4)╔═══╤═══════════════════╤═══════════════════╤═══════════════════╤═══════════════════╗║ │ A │ B │ C_cummax │ D_cummax ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 3 │ foo │ two │ 5 │ 5 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 4 │ foo │ three │ 7 │ 8 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 5 │ bar │ one │ 3 │ 2 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 6 │ bar │ two │ 2 │ 6 ║╟───┼───────────────────┼───────────────────┼───────────────────┼───────────────────╢║ 7 │ bar │ three │ 4 │ 1 ║╚═══╧═══════════════════╧═══════════════════╧═══════════════════╧═══════════════════╝