I have a pandas DataFrame with one list-column, say:
df = pd.DataFrame({"pairs": [["A|B", "B|C", "C|D", "D|F"], ["A|D", "D|F", "F|G", "G|D"], ["C|D", "D|X"]]})
The lists in the pairs column always contain consecutive pairs, where the 2 elements of the pairs are separated by a |. I want to kind of "flatten" the lists in these columns, by instead of storing the pairs, now storing the elements of the pairs in the same order. So the desired DataFrame looks like:
elements
[A, B, C, D, F]
[A, D, F, G, D]
[C, D, X]
(Edited: I also would like to have elements occur multiple times in a resulting list, like D in the second row)
This looks so simple and I can't believe there wouldn't be an efficient solution to this, but so far I have failed to find any python method that could help me