0

I have a field within an array as below.

 |-- col1: string (nullable = true)
 |-- col2: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- cola: string (nullable = true)
 |    |    |-- colb: string (nullable = true)

I have done some calculation on colb using myudf which is within the array col2.

myDF=myDF.withColumn(colb, myudf(colb))

When I use withColumn, it creates a new column but I want to replace the existing column with new value. Can anyone suggest how this can be done.

 |-- col1: string (nullable = true)
 |-- col2: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- cola: string (nullable = true)
 |    |    |-- colb: string (nullable = true)
 |-- colb: array (nullable = true)
jakrm
  • 183
  • 2
  • 3
  • 11
  • Possible duplicate of [Change value of nested column in DataFrame](https://stackoverflow.com/questions/50123771/change-value-of-nested-column-in-dataframe) – cronoik Oct 09 '19 at 14:23
  • Unfortunately, it does not address how to add to an array. Can you please help. – jakrm Oct 09 '19 at 14:44

0 Answers0