pyspark.sql.functions.log

pyspark.sql.functions.log(arg1: Union[ColumnOrName, float], arg2: Optional[ColumnOrName] = None) → pyspark.sql.column.Column[source]

Returns the first argument-based logarithm of the second argument.

If there is only one argument, then this takes the natural logarithm of the argument.

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
arg1Column, str or float

base number or actual number (in this case base is e)

arg2Column, str or float

number to calculate logariphm for.

Returns
Column

logariphm of given value.

Examples

>>> df = spark.createDataFrame([10, 100, 1000], "INT")
>>> df.select(log(10.0, df.value).alias('ten')).show() 
+---+
|ten|
+---+
|1.0|
|2.0|
|3.0|
+---+

And Natural logarithm

>>> df.select(log(df.value)).show() 
+-----------------+
|        ln(value)|
+-----------------+
|2.302585092994046|
|4.605170185988092|
|4.605170185988092|
+-----------------+