Skip to main content
Version: Python

ungroup

ungroup ungroups column content. It is the opposite of the group_by method. ungroup expands columns containing either Deephaven arrays or Java arrays into columns of singular values.

caution

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

Syntax

table.ungroup(cols: Union[str, list[str]]) -> Table

Parameters

ParameterTypeDescription
cols optionalUnion[str, list[str]]

The column(s) of data to ungroup.

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

Returns

A new table in which array columns from the source table are expanded 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 expanded 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]),
]
)

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

result = array_table.ungroup()

In this example, group_by returns an array of values for each column, as grouped by X, while ungroup will expand 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]),
]
)

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

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