1

I want to create a new column(not from an existing columns) having MapType(StringType(),StringType()) how do I achieve this.

So far, I was able to write the below code but it's not working.

df = df.withColumn("normalizedvariation",lit(None).cast(MapType(StringType(),StringType())))

Also I would like to know the different methods to achieve the same, Thank you.

1 Answer 1

2

This is one way you can try, newMapColumn here woukld be the name of the Map column. You can see the output I got below. If that is not what you are looking for, please let me know. Thanks!

Also you will have to import the functions using the below line:
from pyspark.sql.functions import col,lit,create_map

enter image description here

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.