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’, ‘UTF-32’).
New in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters
- col
Column
or column name target column to work on.
- charsetliteral string
charset to use to encode.
- col
- Returns
Column
the column for computed results.
See also
Examples
>>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([("abcd",)], ["c"]) >>> df.select("*", sf.encode("c", "UTF-8")).show() +----+----------------+ | c|encode(c, UTF-8)| +----+----------------+ |abcd| [61 62 63 64]| +----+----------------+