1

I want to rename a column using spark data frame and add a condition.

For example: I have a column "Code" which I want to rename to "Source Code" and I want to add a condition. When the values in the column equal "A" it should be renamed to "Agent" and when the value is "O" it should be renamed to "Other".

SFatima
  • 117
  • 1
  • 4
  • 12

1 Answers1

2

renaming column

df.withColumnRenamed("oldName", "newName")

updating value

val newColumnValue = df("c")... //some calculation
df.withColumn("updatedValue", newColumn)
Natalia
  • 4,362
  • 24
  • 25