move_columns
The move_columns
method creates a new table with specified columns moved to a specific column index value.
Syntax
move_columns(idx: int, cols: Union[str, Sequence[str]]) -> Table
Parameters
Parameter | Type | Description |
---|---|---|
idx | int | Column index where the specified columns will be moved in the new table. The index is zero-based, so column index number 2 would be the third column. |
cols | Union[str, Sequence[str]] | Columns to be moved. |
Returns
A new table with specified columns moved to a specific column index value.
Examples
The following example moves column C
to the second position (1st index) in the new table.
from deephaven import new_table
from deephaven.column import string_col, int_col
source = new_table(
[
string_col("A", ["apple", "apple", "orange", "orange", "plum", "plum"]),
int_col("B", [1, 1, 2, 2, 3, 3]),
string_col(
"C", ["Macoun", "Opal", "Navel", "Cara Cara ", "Greengage", "Mirabelle"]
),
int_col("D", [1, 2, 12, 3, 2, 3]),
]
)
result = source.move_columns(idx=1, cols=["C"])
- source
- result
The following example moves columns B
and C
to the second position (1st index) and third position in the new table.
from deephaven import new_table
from deephaven.column import string_col, int_col
source = new_table(
[
string_col("A", ["apple", "apple", "orange", "orange", "plum", "plum"]),
int_col("B", [1, 1, 2, 2, 3, 3]),
string_col(
"C", ["Macoun", "Opal", "Navel", "Cara Cara ", "Greengage", "Mirabelle"]
),
int_col("D", [1, 2, 12, 3, 2, 3]),
]
)
result = source.move_columns(idx=1, cols=["C", "D"])
- source
- result