pyspark.sql.functions.
log
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.
Column
base number or actual number (in this case base is e)
number to calculate logariphm for.
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| +-----------------+