pyspark.sql.functions.ascii#

pyspark.sql.functions.ascii(col)[source]#

Computes the numeric value of the first character of the string column.

Added in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters:
colColumn or column name

target column to work on. A column that evaluates to a string.

Returns:
Column

numeric value. Returns a column that evaluates to an integer.

Examples

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame(["Spark", "PySpark", "Pandas API"], "STRING")
>>> df.select("*", sf.ascii("value")).show()
+----------+------------+
|     value|ascii(value)|
+----------+------------+
|     Spark|          83|
|   PySpark|          80|
|Pandas API|          80|
+----------+------------+