pyspark.sql.functions.exp#

pyspark.sql.functions.exp(col)[source]#

Computes the exponential of the given value.

New in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or column name

column to calculate exponential for.

Returns
Column

exponential of the given value.

Examples

Example 1: Compute the exponential

>>> from pyspark.sql import functions as sf
>>> df = spark.sql("SELECT id AS value FROM RANGE(5)")
>>> df.select("*", sf.exp(df.value)).show()
+-----+------------------+
|value|        EXP(value)|
+-----+------------------+
|    0|               1.0|
|    1|2.7182818284590...|
|    2|  7.38905609893...|
|    3|20.085536923187...|
|    4|54.598150033144...|
+-----+------------------+

Example 2: Compute the exponential of invalid values

>>> from pyspark.sql import functions as sf
>>> spark.sql(
...     "SELECT * FROM VALUES (FLOAT('NAN')), (NULL) AS TAB(value)"
... ).select("*", sf.exp("value")).show()
+-----+----------+
|value|EXP(value)|
+-----+----------+
|  NaN|       NaN|
| NULL|      NULL|
+-----+----------+