verticapy.vDataFrame.abs#
- vDataFrame.abs(columns: str | list[str] | None = None) vDataFrame #
Applies the absolute value function to all input vDataColumns.
Parameters#
- columns: SQLColumns, optional
List of the vDataColumns names. If empty, all numerical vDataColumns are used.
Returns#
- vDataFrame
self
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" : [10, -10, 20, -2]})
123valInteger100%1 10 2 -10 3 20 4 -2 Now we can convert all to absolute values:
vdf.abs()
123valInteger100%1 10 2 10 3 20 4 2 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"] = "ABS(val)"
See also
vDataFrame.
analytic()
: Advanced Analytical functions.