pyspark.sql.functions.expm1#
- pyspark.sql.functions.expm1(col)[source]#
Computes the exponential of the given value minus one.
New in version 1.4.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- col
Column
or column name column to calculate exponential for.
- col
- Returns
Column
exponential less one.
Examples
Example 1: Compute the exponential minus one
>>> from pyspark.sql import functions as sf >>> df = spark.sql("SELECT id AS value FROM RANGE(5)") >>> df.select("*", sf.expm1(df.value)).show() +-----+------------------+ |value| EXPM1(value)| +-----+------------------+ | 0| 0.0| | 1| 1.718281828459...| | 2| 6.38905609893...| | 3|19.085536923187...| | 4|53.598150033144...| +-----+------------------+
Example 2: Compute the exponential minus one of invalid values
>>> from pyspark.sql import functions as sf >>> spark.sql( ... "SELECT * FROM VALUES (FLOAT('NAN')), (NULL) AS TAB(value)" ... ).select("*", sf.expm1("value")).show() +-----+------------+ |value|EXPM1(value)| +-----+------------+ | NaN| NaN| | NULL| NULL| +-----+------------+