withField
構造体の列にフィールドを追加または置換します。
構文
Python
withField(fieldName, col)
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
| str | 追加または置換するフィールドの名前 |
| 列 | フィールド値の列式 |
戻り値
列
例
Python
from pyspark.sql import Row
from pyspark.sql.functions import lit
df = spark.createDataFrame([Row(a=Row(b=1, c=2))])
df.withColumn('a', df['a'].withField('b', lit(3))).select('a.b').show()
Output
# +---+
# | b|
# +---+
# | 3|
# +---+
Python
df.withColumn('a', df['a'].withField('d', lit(4))).select('a.d').show()
Output
# +---+
# | d|
# +---+
# | 4|
# +---+