pyspark.sql.functions.log10#
- pyspark.sql.functions.log10(col)[source]#
- Computes the logarithm of the given value in Base 10. - New in version 1.4.0. - Changed in version 3.4.0: Supports Spark Connect. - Parameters
- colColumnor column name
- column to calculate logarithm for. 
 
- col
- Returns
- Column
- logarithm of the given value in Base 10. 
 
 - Examples - Example 1: Compute the logarithm in Base 10 - >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([(1,), (10,), (100,)], ["value"]) >>> df.select("*", sf.log10(df.value)).show() +-----+------------+ |value|LOG10(value)| +-----+------------+ | 1| 0.0| | 10| 1.0| | 100| 2.0| +-----+------------+ - Example 2: Compute the logarithm in Base 10 of invalid values - >>> from pyspark.sql import functions as sf >>> spark.sql( ... "SELECT * FROM VALUES (-1), (0), (FLOAT('NAN')), (NULL) AS TAB(value)" ... ).select("*", sf.log10("value")).show() +-----+------------+ |value|LOG10(value)| +-----+------------+ | -1.0| NULL| | 0.0| NULL| | NaN| NaN| | NULL| NULL| +-----+------------+