verticapy.vDataColumn.apply_fun#
- vDataColumn.apply_fun(func: Literal['abs', 'acos', 'asin', 'atan', 'avg', 'cbrt', 'ceil', 'contain', 'count', 'cos', 'cosh', 'cot', 'dim', 'exp', 'find', 'floor', 'len', 'length', 'ln', 'log', 'log10', 'max', 'mean', 'mod', 'min', 'pow', 'round', 'sign', 'sin', 'sinh', 'sum', 'sqrt', 'tan', 'tanh'], x: bool | float | str | timedelta | datetime = 2) vDataFrame #
Applies a default function to the vDataColumn.
Parameters#
- func: str
Function to use to transform the vDataColumn.
- abs:
absolute value
- acos:
trigonometric inverse cosine
- asin:
trigonometric inverse sine
- atan:
trigonometric inverse tangent
- avg / mean:
average
- cbrt:
cube root
- ceil:
value up to the next whole number
- contain:
checks if
x
is in the collection
- count:
number of non-null elements
- cos:
trigonometric cosine
- cosh:
hyperbolic cosine
- cot:
trigonometric cotangent
- dim:
dimension (only for arrays)
- exp:
exponential function
- find:
returns the ordinal position of a specified element in an array (only for arrays)
- floor:
value down to the next whole number
- len / length:
length
- ln:
natural logarithm
- log:
logarithm
- log10:
base 10 logarithm
- max:
maximum
- min:
minimum
- mod:
remainder of a division operation
- pow:
number raised to the power of another number
- round:
rounds a value to a specified number of decimal places
- sign:
arithmetic sign
- sin:
trigonometric sine
- sinh:
hyperbolic sine
- sqrt:
arithmetic square root
- sum:
sum
- tan:
trigonometric tangent
- tanh:
hyperbolic tangent
- x: PythonScalar, optional
If the function has two arguments (example, power or mod),
x
represents the second argument.
Returns#
- vDataFrame
self._parent
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 float values:
vdf = vp.vDataFrame({"val" : [0.2, 10.6, 20.1]})
123valNumeric(5)100%1 0.2 2 10.6 3 20.1 A
ceil
function can be conveniently applied using theapply_fun
function. Below, we can round off the values of “val” column:vdf["val"].apply_fun("ceil")
123valNumeric(5)100%1 1.0 2 11.0 3 21.0 Note
Applying a function will alter the
vDataColumn
structure. It’s advisable to check the current relation of thevDataFrame
to ensure it aligns with the intended outcome. For more information on achieving that, check out thecurrent_relation
documentation.See also