Skip to main content
Version: Python

abs_sum_by

abs_sum_by creates a new table containing the absolute sum for each group.

Syntax

table.abs_sum_by(by: Sequence[str] = None) -> Table

Parameters

ParameterTypeDescription
by optionalUnion[str, Sequence[str]]

The column(s) by which to group data. Default is None.

Returns

A new table containing the absolute sum for each group.

Examples

In this example, abs_sum_by returns the absolute sum of the whole table.

from deephaven import new_table
from deephaven.column import string_col, int_col

source = new_table(
[
int_col("Number1", [100, -44, 49, 11, -66, 50, 29, 18, -70]),
int_col("Number2", [-55, 76, 20, 130, 230, -50, 73, 137, 214]),
]
)

result = source.abs_sum_by()

In this example, abs_sum_by returns the absolute sum, as grouped by X. Because a sum can not be computed for the string column Y, this column is dropped before applying abs_sum_by.

from deephaven import new_table
from deephaven.column import string_col, int_col

source = new_table(
[
string_col("X", ["A", "B", "A", "C", "B", "A", "B", "B", "C"]),
string_col("Y", ["M", "N", "O", "N", "P", "M", "O", "P", "M"]),
int_col("Number1", [100, -44, 49, 11, -66, 50, 29, 18, -70]),
int_col("Number2", [-55, 76, 20, 130, 230, -50, 73, 137, 214]),
]
)

result = source.drop_columns(cols=["Y"]).abs_sum_by(by=["X"])