Skip to main content

conv

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

For the corresponding Databricks SQL function, see conv function.

Syntax

Python
from pyspark.databricks.sql import functions as dbf

dbf.conv(col=<col>, fromBase=<fromBase>, toBase=<toBase>)

Parameters

Parameter

Type

Description

col

pyspark.sql.Column or str

a column to convert base for.

fromBase

int

from base number.

toBase

int

to base number.

Returns

pyspark.sql.Column: logariphm of given value.

Examples

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