columnsToRows
The columnsToRows
method is used to convert a table's columns into rows.
Syntax
columnsToRows(source, labelColumn, valueColumns, labels, transposeColumns)
columnsToRows(source, labelColumn, valueColumn, transposeColumns...)
columnsToRows(source, labelColumn, valueColumn, labels, transposeColumns)
Parameters
Parameter | Type | Description |
---|---|---|
source | Table | The table with multiple value columns. |
labelColumn | String | The output column name for the label column. |
valueColumns | String[] | The output column names for the value columns. For each output value column, all of the constituent input columns columns must have the same type. If the types are different, then an |
valueColumn | String | The output column name for the value column. For each output value column, all of the constituent input columns columns must have the same type. If the types are different, then an |
labels | String[] | The labels for the transposed columns. Must be parallel to |
transposeColumns | String[][] | An array parallel to |
transposeColumns | String[] | The input column names to transpose. Must be parallel to |
transposeColumns | String... | The names of the columns to transpose. The label value is the name of the column. |
Returns
The transformed table.
Example
In this example, we start with a table that is very wide compared to how tall it is. The information in the table would be easier to read if we reorganize it, which we will do with the columnsToRows
method.
import io.deephaven.engine.table.impl.util.ColumnsToRowsTransform
source = newTable(
stringCol("Sym", "AAPL", "SPY"),
intCol("Val1", 1, 2),
doubleCol("D1", 7.7, 8.8),
doubleCol("D2", 9.9, 10.1),
intCol("Val2", 3, 4),
intCol("Val3", 5, 6),
doubleCol("D3", 11.11, 12.12)
)
result = ColumnsToRowsTransform.columnsToRows(
source,
"Name",
new String[]{"IntVal", "DubVal"},
new String[]{"A", "B", "C"},
new String[][]{new String[]{"Val1", "Val2", "Val3"},
new String[]{"D1", "D2", "D3"}}
)
- result
- source