pyspark.sql.DataFrame.selectExpr

DataFrame.selectExpr(*expr: Union[str, List[str]]) → pyspark.sql.dataframe.DataFrame[source]

Projects a set of SQL expressions and returns a new DataFrame.

This is a variant of select() that accepts SQL expressions.

New in version 1.3.0.

Examples

>>> df.selectExpr("age * 2", "abs(age)").collect()
[Row((age * 2)=4, abs(age)=2), Row((age * 2)=10, abs(age)=5)]