Loading...

vastorbit.VastFrame.swap

VastFrame.swap(column1: int | str, column2: int | str) VastFrame

Swap the two input VastColumns.

Parameters:
  • column1 (str | int) – The first VastColumn or its index to swap.

  • column2 (str | int) – The second VastColumn or its index to swap.

Returns:

self

Return type:

VastFrame

Examples

Let’s begin by importing vastorbit.

import vastorbit as vo

Hint

By assigning an alias to vastorbit, we mitigate the risk of code collisions with other libraries. This precaution is necessary because vastorbit uses commonly known function names like “average” and “median”, which can potentially lead to naming conflicts. The use of an alias ensures that the functions from vastorbit are used as intended without interfering with functions from other libraries.

Let us create a dummy dataset and swap its columns:

vdf = vo.VastFrame(
    {
        "val" : [0, 10, 20],
        "cat": ['a', 'b', 'c'],
    },
)
123
val
Integer
Abc
cat
Varchar(1)
110b
220c
30a
Rows: 1-3 | Columns: 2

We can swap the categorical column and value columns:

vdf.swap("val", "cat")
Abc
cat
Varchar(1)
123
val
Integer
1b10
2c20
3a0
Rows: 1-3 | Columns: 2

See also

VastFrame.info() : Displays information about the different VastFrame transformations