pyspark.sql.functions.conv#

pyspark.sql.functions.conv(col, fromBase, toBase)[source]#

Convert a number in a string column from one base to another.

Added in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters:
colColumn or str

a column to convert base for. A column that evaluates to a string.

fromBase: int

from base number. A column that evaluates to an integer.

toBase: int

to base number. A column that evaluates to an integer.

Returns:
Column

logariphm of given value. Returns a column that evaluates to a string.

Examples

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([("010101",), ( "101",), ("001",)], ['n'])
>>> df.select("*", sf.conv(df.n, 2, 16)).show()
+------+--------------+
|     n|conv(n, 2, 16)|
+------+--------------+
|010101|            15|
|   101|             5|
|   001|             1|
+------+--------------+