pyspark.sql.functions.expr#

pyspark.sql.functions.expr(str)[source]#

Parses the expression string into the column that it represents

New in version 1.5.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
strstr

expression defined in string.

Returns
Column

column representing the expression.

Examples

>>> df = spark.createDataFrame([["Alice"], ["Bob"]], ["name"])
>>> df.select("name", expr("length(name)")).show()
+-----+------------+
| name|length(name)|
+-----+------------+
|Alice|           5|
|  Bob|           3|
+-----+------------+