0

Working on a Spark Dataframe where I want to adjust the content of a field. Input for the adjustment comes from a list, however, when I pass the information in the list as arguments I get an error:

AssertionError: col should be Column

fld = ["As_Of_Date","date_format('As_Of_Date,'yyyyMMdd')"]

df.withColumn(fld[0],fld[1])

if I pass it directly without the list, it does work. What am I doing wrong and what should I change to make it work?

1 Answer 1

1

You don't need to quote the function date_format here.

fld = ['As_Of_Date',date_format('As_Of_Date','yyyyMMdd')]
df = df.withColumn(fld[0],fld[1])
Sign up to request clarification or add additional context in comments.

1 Comment

check the edit..assignment to the data frame with the transformed column was missing which has been added.

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.