pyspark.sql.functions.log2#
- pyspark.sql.functions.log2(col)[source]#
Returns the base-2 logarithm of the argument.
New in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- col
Column
or str a column to calculate logariphm for.
- col
- Returns
Column
logariphm of given value.
Examples
>>> from pyspark.sql import functions as sf >>> spark.range(10).select("*", sf.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...| +---+------------------+