You can use the native Spark function abs():

from  pyspark.sql.functions import abs

df1 = df.withColumn('Value',abs(df.Value))
df1.show()
+---+-----+
| Id|Value|
+---+-----+
|  a|  5.0|
|  b|  1.0|
|  c|  0.3|
+---+-----+
Answer from mtoto on Stack Overflow
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.functions.abs.html
pyspark.sql.functions.abs — PySpark 4.1.1 documentation
Example 3: Compute the absolute value of an expression · >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([(1, 1), (2, -2), (3, 3)], ["id", "value"]) >>> df.select("*", sf.abs(df.id - df.value)).show() +---+-----+-----------------+ | id|value|abs((id - value))| +---+-----+-----------------+ | 1| 1| 0| | 2| -2| 4| | 3| 3| 0| +---+-----+-----------------+
🌐
Sparkreference
sparkreference.com › reference › abs
Introduction to the abs() function in PySpark - Spark Reference
The abs() function in PySpark is used to compute the absolute value of a numeric column or expression.
🌐
Pysparkisrad
pysparkisrad.com › functions › abs
abs | PySpark Is Rad
Computes the absolute value. 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() Usage: This is just a basic math function.
🌐
DataScience Made Simple
datasciencemadesimple.com › home › absolute value of column in pyspark – abs() function
Absolute value of column in Pyspark - abs() function - DataScience Made Simple
November 17, 2024 - In order to get Absolute value of column in pyspark we use abs() function. abs() function in pyspark gets the absolute value of the column with Examples
🌐
Medium
medium.com › @uzzaman.ahmed › pyspark-mathematical-functions-a-comprehensive-guide-6436921fc55f
PySpark Mathematical Functions: A Comprehensive Guide | by Ahmed Uz Zaman | Medium
March 20, 2023 - Examples of mathematical functions in PySpark include: abs(col): Returns the absolute value of the given value.
Find elsewhere
🌐
Berkeley EECS
people.eecs.berkeley.edu › ~jegonzal › pyspark › pyspark.sql.html
pyspark.sql module — PySpark master documentation
Computes the absolute value. New in version 1.3. ... Computes the cosine inverse of the given value; the returned angle is in the range0.0 through pi. New in version 1.4. pyspark.sql.functions.add_months(start, months)[source]¶
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › api › pyspark.ml.feature.MaxAbsScaler.html
MaxAbsScaler — PySpark 4.1.1 documentation - Apache Spark
class pyspark.ml.feature.MaxAbsScaler(*, inputCol=None, outputCol=None)[source]# Rescale each feature individually to range [-1, 1] by dividing through the largest maximum absolute value in each feature. It does not shift/center the data, and thus does not destroy any sparsity.