Notiz
Zougrëff op dës Säit erfuerdert Autorisatioun. Dir kënnt probéieren, Iech unzemellen oder Verzeechnesser ze änneren.
Zougrëff op dës Säit erfuerdert Autorisatioun. Dir kënnt probéieren, Verzeechnesser ze änneren.
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|
# +---+