My DataFrame looks like as follows:
StudentID Marks
100 ["20", "25.5", "40.23", "50"]
200 ["30", "20", "25", "40"]
300 ["20", "25", "50", "35"]
I need to extract the marks within the array and create a new DataFrame. However, am unable to extract beyond the second value in the DF (don't know how to select all marks via the regex ([0-9]+)(?:\.[0-9]+){3}.
df1.select(regexp_extract('StudentID', '(\w+)(,)', 1).alias("C1"),
regexp_extract('Marks', '([0-9]+)(?:\.[0-9]+){3}', 0).alias("C2"))
Ultimately, need to create a new DataFrame with below format:
StudentID C1 C2 C3 C4
100 20 25.5 40.23 50
200 30 20 25 40
300 20 25 50 35
Thank you in advance.