Share via


log2

Returns the base-2 logarithm of the argument. Supports Spark Connect.

For the corresponding Databricks SQL function, see log2 function.

Syntax

from pyspark.databricks.sql import functions as dbf

dbf.log2(col=<col>)

Parameters

Parameter Type Description
col pyspark.sql.Column or str A column to calculate logarithm for.

Returns

pyspark.sql.Column: logariphm of given value.

Examples

from pyspark.databricks.sql import functions as dbf
spark.range(10).select("*", dbf.log2('id')).show()
+---+------------------+
| id|          LOG2(id)|
+---+------------------+
|  0|              NULL|
|  1|               0.0|
|  2|               1.0|
|  3| 1.584962500721...|
|  4|               2.0|
|  5| 2.321928094887...|
|  6| 2.584962500721...|
|  7| 2.807354922057...|
|  8|               3.0|
|  9|3.1699250014423...|
+---+------------------+