Skip to main content

bin

Returns the string representation of the binary value of the given column. Supports Spark Connect.

For the corresponding Databricks SQL function, see bin function.

Syntax​

Python
from pyspark.sql import functions as dbf

dbf.bin(col=<col>)

Parameters​

Parameter

Type

Description

col

pyspark.sql.Column or str

Target column to work on.

Parameter

Type

Description

col

pyspark.sql.Column or str

Target column to work on.

Returns​

pyspark.sql.Column: binary representation of given value as string.

Examples​

Python
from pyspark.sql import functions as dbf
spark.range(10).select("*", dbf.bin("id")).show()
Output
+---+-------+
| id|bin(id)|
+---+-------+
| 0| 0|
| 1| 1|
| 2| 10|
| 3| 11|
| 4| 100|
| 5| 101|
| 6| 110|
| 7| 111|
| 8| 1000|
| 9| 1001|
+---+-------+