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
Parameter | Type | Description |
---|---|---|
cols optional | Union[str, list[str]] | The column(s) of data to ungroup.
|
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()
- source
- result
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"])
- source
- result