---
title: abs
description: "abs function in PySpark: Computes the absolute value of the given column or expression."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/functions/abs
---

# abs

Computes the absolute value of the given column or expression. Supports Spark Connect.

For the corresponding Databricks SQL function, see [`abs` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/abs.md).

## Syntax

```python
from pyspark.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

```python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(-1,), (-2,), (-3,), (None,)], ["value"])
df.select("*", dbf.abs(df.value)).show()
```

```Output
+-----+----------+
|value|abs(value)|
+-----+----------+
|   -1|         1|
|   -2|         2|
|   -3|         3|
| NULL|      NULL|
+-----+----------+

```

```python
from pyspark.sql import functions as dbf
df = spark.createDataFrame([(-1.5,), (-2.5,), (None,), (float("nan"),)], ["value"])
df.select("*", dbf.abs(df.value)).show()
```

```Output
+-----+----------+
|value|abs(value)|
+-----+----------+
| -1.5|       1.5|
| -2.5|       2.5|
| NULL|      NULL|
|  NaN|       NaN|
+-----+----------+

```
