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’).
Added in version 1.5.0.
Changed in version 3.4.0: Supports Spark Connect.
- Parameters:
- col
Columnor column name target column to work on. A column that evaluates to a string.
- charsetliteral string
charset to use to encode. A column that evaluates to a string.
- col
- Returns:
Columnthe column for computed results. Returns a column that evaluates to a binary.
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]| +----+----------------+