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 fromverticapy
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'], }, )
AbcvalVarchar(8)100%1 Hello 2 Meow 3 Gaza 4 New York We can conveniently get the length of each row in a column:
vdf["val"].get_len()
123val.lengthInteger1 5 2 4 3 4 4 8 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