Loading...

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 x is 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), x represents the second argument.

Returns:

self._parent

Return type:

VastFrame

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 from vastorbit are 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]})
123
val
Decimal(3, 1)
120.1
210.6
30.2
Rows: 1-3 | Column: val | Type: decimal(3, 1)

A ceil function can be conveniently applied using the apply_fun function. Below, we can round off the values of “val” column:

vdf["val"].apply_fun("ceil")
123
val
Decimal(3, 0)
121.0
211.0
31.0
Rows: 1-3 | Column: val | Type: decimal(3, 0)

Note

Applying a function will alter the VastColumn structure. It’s advisable to check the current relation of the VastFrame to ensure it aligns with the intended outcome. For more information on achieving that, check out the current_relation documentation.

See also

VastFrame.applymap() : Applies a function to all VastColumn objects.
VastColumn.apply() : Applies a function to the VastColumn.