Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pyspark Array column to dataframe

i have this urgent problem, i need to transform an array column in pyspark dataframe to a dataframe itself.

Exemple:

Input:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

number values combination
a [e, f, g] [[e, f],[e,g],[f,g]...]
b [e, f, g ,h] [[e, f],[e,g],[f,g],[f,h]...]
c [b, c] [[b, c]]

i want to get in output only the column combination as:

value1 value2
e f
e g
f g
e f
e g
f g
f h
b c

i want the extract line by line in the same dataframe without loop functions.

>Solution :

let’s say input dataframe is df.

from pyspark.sql import functions as F
df = df.select(F.explode(df.combination).alias("values"))
df = df.select(df.values[0].alias('value1'), df.values[1].alias('value2'))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading