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".

3

1 Answer 1

2

renaming column

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

updating value

val newColumnValue = df("c")... //some calculation
df.withColumn("updatedValue", newColumn)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.