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 OverflowApache
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.
Databricks
api-docs.databricks.com › python › pyspark › latest › pyspark.sql › api › pyspark.sql.functions.abs.html
pyspark.sql.functions.abs — PySpark master documentation
Computes the absolute value · pyspark.sql.functions.sqrt
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.
Apache Software Foundation
archive.apache.org › dist › spark › docs › 3.3.3 › api › python › reference › pyspark.sql › api › pyspark.sql.functions.abs.html
pyspark.sql.functions.abs — PySpark 3.3.3 documentation
pyspark.sql.functions.abs(col: ColumnOrName) → pyspark.sql.column.Column[source]¶
Apache
dlcdn.apache.org › spark › docs › 3.1.2 › api › python › reference › api › pyspark.sql.functions.abs.html
pyspark.sql.functions.abs — PySpark 3.1.2 documentation
pyspark.sql.functions.abs(col)[source]¶ · Computes the absolute value. New in version 1.3.
Apache Software Foundation
archive.apache.org › dist › spark › docs › 3.3.1 › api › python › reference › pyspark.sql › api › pyspark.sql.functions.abs.html
pyspark.sql.functions.abs — PySpark 3.3.1 documentation
pyspark.sql.functions.abs(col: ColumnOrName) → pyspark.sql.column.Column[source]¶
Apache Software Foundation
archive.apache.org › dist › spark › docs › 3.4.4 › api › python › reference › pyspark.sql › api › pyspark.sql.functions.abs.html
pyspark.sql.functions.abs — PySpark 3.4.4 documentation
pyspark.sql.functions.abs(col: ColumnOrName) → pyspark.sql.column.Column[source]¶
Ati
mirror.ati.tn › apache › spark › docs › 3.2.2 › api › python › reference › api › pyspark.sql.functions.abs.html
pyspark.sql.functions.abs — PySpark 3.2.2 documentation
pyspark.sql.functions.abs(col)[source]¶ · Computes the absolute value. New in version 1.3.
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.
Databricks
api-docs.databricks.com › python › pyspark › latest › pyspark.pandas › api › pyspark.pandas.Series.abs.html
pyspark.pandas.Series.abs — PySpark master documentation
Return a Series/DataFrame with absolute numeric value of each element · Absolute numeric values in a Series