The current spark data frame has CSV values in cell level of one column, I trying to explode it to new columns. The example dataframe
a_id features
1 2020 "a","b","c","d","constant1","1","0.1","aa"
2 2021 "a","b","c","d","constant2","1","0.2","ab"
3 2022 "a","b","c","d","constant3","1","0.3","ac","a","b","c","d","constant3","1.1","3.3","acx"
4 2023 "a","b","c","d","constant4","1","0.4","ad"
5 2024 "a","b","c","d","constant5","1","0.5","ae","a","b","c","d","constant5","1.2","6.3","xwy","a","b","c","d","constant5","2.2","8.3","bunr"
6 2025 "a","b","c","d","constant6","1","0.6","af"
The features column has multiple csv values, and in it (a, b, c, d) act as header and they get repeated in some cells (in row 3 and 5), I want to extract only one header and its respective values. The output of the expected dataframe is as shown
Output spark dataframe
a_id a d
1 2020 constant1 ["aa"]
2 2021 constant2 ["ab"]
3 2022 constant3 ["ac","acx"]
4 2023 constant4 ["ad"]
5 2024 constant5 ["ae","xwy","bunr"]
6 2025 constant6 ["af"]
As shown, I would like to extract only a and d headers as new columns, where a is constant and d has multiple values, where its values made as list.
Please help how to convert this in pysaprk. The above dataframe is streaming dataframe in real time.