Kopīgot, izmantojot


abs

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.databricks.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.databricks.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.databricks.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|
+-----+----------+