verticapy.vDataColumn.round#
- vDataColumn.round(n: int) vDataFrame #
Rounds the vDataColumn by keeping only the input number of digits after the decimal point.
Parameters#
- n: int
Number of digits to keep after the decimal point.
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.21, 11.26, 20.21]})
123valNumeric(6)100%1 0.21 2 11.26 3 20.21 AWe can conveniently round off the numbers and select the decimal point as well using
n
:vdf["val"].round(n = 1)
123valNumeric(6)100%1 0.2 2 11.3 3 20.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"] = "ROUND(val, 1)"
See also