0

I would like to transform a table with a column as array of strings on databricks pyspark.

my table:

 id         values  (array<string>)
 rgf        ['vwervfrev', 'fweccf', 'tuyhert']
 rty        ['evvverws', 'ilonmunt', 'cedcrhb']

What I need:

 id         values
 rdf        'vwervfrev'
 rdf        'fweccf'
 rdf        'tuyhert'
 rty        'evvverws'
 rty        'ilonmunt'
 rty        'cedcrhb'

I am not sure how to do the transformation ?

thanks

1

1 Answer 1

1

You can do this with the explode function:

from pyspark.sql.functions import explode, col

new_df = df.withColumn("values", explode(col("values")))
new_df.show()

https://spark.apache.org/docs/latest/api/python/_modules/pyspark/sql/functions.html#explode

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.