selectExpr
一連のSQL式を投影し、新しいDataFrameを返します。
構文
selectExpr(*expr: Union[str, List[str]])
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
| 文字列または文字列のリスト | 投影するSQL式文字列。 |
戻り値
DataFrame: 式によって変換された新しい列と古い列を含むDataFrame 。
例
Python
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|
# +---------+--------+