0

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
  • 107
  • 1
  • 4
  • 11

1 Answers1

1

renaming column

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

updating value

val newColumnValue = df("c")... //some calculation
df.withColumn("updatedValue", newColumn)
Natalia
  • 3,790
  • 23
  • 25