pyspark.sql.functions.abs

pyspark.sql.functions.abs(col: ColumnOrName) → pyspark.sql.column.Column[source]

Computes the absolute value.

New in version 1.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

target column to compute on.

Returns
Column

column for computed results.

Examples

>>> df = spark.range(1)
>>> df.select(abs(lit(-1))).show()
+-------+
|abs(-1)|
+-------+
|      1|
+-------+