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.
Add or replace a field in a struct column.
Syntax
withField(fieldName, col)
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldName |
str | Name of the field to add or replace |
col |
Column | Column expression for the field value |
Returns
Column
Examples
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()
# +---+
# | b|
# +---+
# | 3|
# +---+
df.withColumn('a', df['a'].withField('d', lit(4))).select('a.d').show()
# +---+
# | d|
# +---+
# | 4|
# +---+