Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Projects a set of SQL expressions and returns a new DataFrame.
Syntax
selectExpr(*expr: Union[str, List[str]])
Parameters
| Parameter | Type | Description |
|---|---|---|
expr |
str or list of str | SQL expression strings to project. |
Returns
DataFrame: 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|
# +---------+--------+