Loading...

verticapy.vDataColumn.get_len#

vDataColumn.get_len() vDataColumn#

Returns a new vDataColumn that represents the length of each element.

Returns#

vDataColumn

vDataColumn that includes the length of each element.

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 with negative values:

vdf = vp.vDataFrame(
    {
        "val" : ['Hello', 'Meow', 'Gaza', 'New York'],
    },
)

Abc
val
Varchar(8)
100%
1Hello
2Meow
3Gaza
4New York

We can conveniently get the length of each row in a column:

vdf["val"].get_len()
123
val.length
Integer
15
24
34
48

Note

While the same task can be accomplished using pure SQL (see below), adopting a Pythonic approach can offer greater convenience and help avoid potential syntax errors.

vdf["val"] = "LENGTH(val)"

See also

vDataColumn.date_part() : Extracts a specific TS field from the vDataColumn.