vastorbit.VastColumn.apply_fun¶
- VastColumn.apply_fun(func: Literal['abs', 'acos', 'asin', 'atan', 'avg', 'cbrt', 'ceil', 'contains', 'count', 'cos', 'cosh', 'cot', 'cardinality', 'exp', 'element_at', 'floor', 'len', 'length', 'ln', 'log', 'log10', 'max', 'mean', 'mod', 'min', 'pow', 'power', 'round', 'sign', 'sin', 'sinh', 'sum', 'sqrt', 'tan', 'tanh'], x: Annotated[bool | float | str | timedelta | datetime, 'Python Scalar'] = 2) VastFrame¶
Applies a default function to the VastColumn.
- Parameters:
func (str) –
Function to use to transform the VastColumn.
- 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
- contains:
checks if
xis in the array
- count:
number of non-null elements
- cos:
trigonometric cosine
- cosh:
hyperbolic cosine
- cot:
trigonometric cotangent
- cardinality:
number of elements in array
- exp:
exponential function
- element_at:
returns element at specified position in array
- floor:
value down to the next whole number
- len / length:
length of string or array
- ln:
natural logarithm
- log:
logarithm
- log10:
base 10 logarithm
- max:
maximum
- min:
minimum
- mod:
remainder of a division operation
- pow / power:
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),
xrepresents the second argument.
- Returns:
self._parent
- Return type:
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 fromvastorbitare used as intended without interfering with functions from other libraries.Let us create a dummy dataset with float values:
vdf = vo.VastFrame({"val" : [0.2, 10.6, 20.1]})
123valDecimal(3, 1)1 20.1 2 10.6 3 0.2 Rows: 1-3 | Column: val | Type: decimal(3, 1)A
ceilfunction can be conveniently applied using theapply_funfunction. Below, we can round off the values of “val” column:vdf["val"].apply_fun("ceil")
123valDecimal(3, 0)1 21.0 2 11.0 3 1.0 Rows: 1-3 | Column: val | Type: decimal(3, 0)Note
Applying a function will alter the
VastColumnstructure. It’s advisable to check the current relation of theVastFrameto ensure it aligns with the intended outcome. For more information on achieving that, check out thecurrent_relationdocumentation.See also