Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
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
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
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([("010101",), ( "101",), ("001",)], ['n'])
df.select("*", dbf.conv(df.n, 2, 16)).show()
+------+--------------+
| n|conv(n, 2, 16)|
+------+--------------+
|010101| 15|
| 101| 5|
| 001| 1|
+------+--------------+