pyspark.sql.functions.encode#

pyspark.sql.functions.encode(col, charset)[source]#

Computes the first argument into a binary from a string using the provided character set (one of ‘US-ASCII’, ‘ISO-8859-1’, ‘UTF-8’, ‘UTF-16BE’, ‘UTF-16LE’, ‘UTF-16’).

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

target column to work on.

charsetstr

charset to use to encode.

Returns
Column

the column for computed results.

Examples

>>> df = spark.createDataFrame([('abcd',)], ['c'])
>>> df.select(encode("c", "UTF-8")).show()
+----------------+
|encode(c, UTF-8)|
+----------------+
|   [61 62 63 64]|
+----------------+