concept selectExpr() in category pyspark

appears as: selectExpr()
Data Analysis with Python and PySpark

This is an excerpt from Manning's book Data Analysis with Python and PySpark.

Listing 7.17. Replacing selectExpr() by a regular select() in our final program
full_data = full_data.selectExpr(
    F.col("model"),
    (F.col("capacity_bytes") / F.pow(F.lit(1024), 3)).alias("capacity_GB"),
    F.col("date"),
    F.col("failure")
)

The second one is simply called expr(). It wraps a SQL-style expression into a column. This is kind of a generalized selectExpr(), where you can use it in lieu of of F.col() (or the column name) when you want to modify a column. If we take our failures table from listing 7.17, we can use an expr (or expression) as the agg() argument. This alternative syntax is shown in listing 7.19. I like doing it in agg() parameters, because it saves a lot of alias().