vastorbit.VastColumn.round¶
- VastColumn.round(n: int) VastFrame¶
Rounds the VastColumn 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:
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.21, 11.26, 20.21]})
123valDecimal(4, 2)1 20.21 2 11.26 3 0.21 Rows: 1-3 | Column: val | Type: decimal(4, 2)AWe can conveniently round off the numbers and select the decimal point as well using
n:vdf["val"].round(n = 1)
123valDecimal(5, 2)1 11.3 2 0.2 3 20.2 Rows: 1-3 | Column: val | Type: decimal(5, 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