Skip to main content
Version: Python

ungroup

ungroup ungroups column content. It is the inverse of the group_by method. ungroup unwraps columns containing either Deephaven arrays or java arrays.

caution

Arrays of different lengths within a row result in an error.

Syntax

table.ungroup(by: List[str]=[])

Parameters

ParameterTypeDescription
by optionalList[str]

The column(s) by which to ungroup data.

  • [] all array columns from the source table will be unwrapped (default).
  • ["X"] will unwrap column X.
  • ["X", "Y"] will unwrap columns X and Y.

Returns

A new table in which array columns from the source table are unwrapped into separate rows.

Examples

In this example, group_by returns an array of values for each column, as grouped by X. ungroup will undo this operation and all array columns from the source table are unwrapped into separate rows

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("Number", [55, 76, 20, 130, 230, 50, 73, 137, 214]),
])

arrayTable = source.group_by(by=["X"])

result = arrayTable.ungroup()

In this example, group_by returns an array of values for each column, as grouped by X, while ungroup will unwrap the created array Y so each element is a new row.

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("Number", [55, 76, 20, 130, 230, 50, 73, 137, 214]),
])

arrayTable = source.group_by(by=["X"])

result = arrayTable.ungroup(cols=["Y"])