0

I have a pyspark dataframe which has two columns. I want to populate one column with a fix value if row value in other column is null. So in customer_df if customer_address is null then populate city column as 'unknown'

I am trying this

customer_df = customer_df.withColumn('city',when(customer_df.customer_address == '','unknown')

But this gives syntax error. What is that I am missing here? Thanks in advance

1 Answer 1

3
customer_df = customer_df.withColumn('city', 
    when(col(customer_address).isNull(), 'unknown').otherwise(col('city'))
  )

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.