comCampo
Adicionar ou substituir um campo em uma coluna de estrutura.
Sintaxe
Python
withField(fieldName, col)
Parâmetros
Parâmetro | Tipo | Descrição |
|---|---|---|
| str | Nome do campo a ser adicionado ou substituído |
| Coluna | Expressão da coluna para o valor do campo |
Devoluções
Coluna
Exemplos
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|
# +---+