abs

abs #

pyspark.sql.functions.abs(col) #

version: since 1.3

Computes the absolute value.

abs

Runnable Code:

from pyspark.sql import functions as F
# Set up dataframe
data = [{"num": 1},{"num": -2},{"num": 0}]
df = spark.createDataFrame(data)
# Use function
df = (df
     .withColumn("absolute", F.abs("num"))
     )
df.show()
num absolute
1 1
-2 2
0 0

Usage:

This is just a basic math function. Nothing special about it. I’ve used it before when doing subtraction between two columns.



returns: \_invoke_function_over_column("abs", col)

PySpark manual

tags: absolute, positive, negative, positive value




© 2023 PySpark Is Rad