DataFrame.
selectExpr
Projects a set of SQL expressions and returns a new DataFrame.
DataFrame
This is a variant of select() that accepts SQL expressions.
select()
New in version 1.3.0.
Changed in version 3.4.0: Supports Spark Connect.
A DataFrame with new/old columns transformed by expressions.
Examples
>>> df = spark.createDataFrame([ ... (2, "Alice"), (5, "Bob")], schema=["age", "name"]) >>> df.selectExpr("age * 2", "abs(age)").show() +---------+--------+ |(age * 2)|abs(age)| +---------+--------+ | 4| 2| | 10| 5| +---------+--------+