Nota
L-aċċess għal din il-paġna jeħtieġ l-awtorizzazzjoni. Tista’ tipprova tidħol jew tibdel id-direttorji.
L-aċċess għal din il-paġna jeħtieġ l-awtorizzazzjoni. Tista’ tipprova tibdel id-direttorji.
Computes the absolute value of the given column or expression. Supports Spark Connect.
For the corresponding Databricks SQL function, see abs function.
Syntax
from pyspark.sql import functions as dbf
dbf.abs(col=<col>)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or column name |
The target column or expression to compute the absolute value on. |
Returns
pyspark.sql.Column: A new column object representing the absolute value of the input.
Examples
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(-1,), (-2,), (-3,), (None,)], ["value"])
df.select("*", dbf.abs(df.value)).show()
+-----+----------+
|value|abs(value)|
+-----+----------+
| -1| 1|
| -2| 2|
| -3| 3|
| NULL| NULL|
+-----+----------+
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(-1.5,), (-2.5,), (None,), (float("nan"),)], ["value"])
df.select("*", dbf.abs(df.value)).show()
+-----+----------+
|value|abs(value)|
+-----+----------+
| -1.5| 1.5|
| -2.5| 2.5|
| NULL| NULL|
| NaN| NaN|
+-----+----------+