ascii #
pyspark.sql.functions.ascii(col) #
version: since 1.5.0
Computes the numeric value of the first character of the string column.
Runnable Code:
from pyspark.sql import functions as F
# Set up dataframe
data = [{"b": "hi","a": "aa"},{"a": ""},{"b": "bob"}]
df = spark.createDataFrame(data).drop("b")
# Use function
df = (df
.withColumn("ascii",
F.ascii(F.col("a")))
)
df.show()
a | ascii |
---|---|
aa | 97 |
0 | |
null | null |
Usage:
Simple function. Just gets the ascii code of the first letter.
returns: \_invoke_function_over_column("ascii", col)
tags: ascii code, utf8, unicode
© 2023 PySpark Is Rad
draft: true def ascii(col): """ Computes the numeric value of the first character of the string column. """ return _invoke_function_over_column(“ascii”, col)
[docs]@since(1.5)