Loading...

verticapy.vDataFrame.swap#

vDataFrame.swap(column1: int | str, column2: int | str) vDataFrame#

Swap the two input vDataColumns.

Parameters#

column1: str | int

The first vDataColumn or its index to swap.

column2: str | int

The second vDataColumn or its index to swap.

Returns#

vDataFrame

self

Examples#

Let’s begin by importing VerticaPy.

import verticapy as vp

Hint

By assigning an alias to verticapy, we mitigate the risk of code collisions with other libraries. This precaution is necessary because verticapy 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 verticapy are used as intended without interfering with functions from other libraries.

Let us create a dummy dataset and swap its columns:

vdf = vp.vDataFrame(
    {
        "val" : [0, 10, 20],
        "cat": ['a', 'b', 'c'],
    },
)

123
val
Integer
100%
Abc
cat
Varchar(1)
100%
10a
210b
320c

We can swap the categorical column and value columns:

vdf.swap("val", "cat")
Abc
cat
Varchar(1)
100%
123
val
Integer
100%
1a0
2b10
3c20

See also

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