I have DF that has multiple columns. Two of the columns are list of the same len.( col2 and col3 are list. the len of the list is the same).
My goal is to list each element on it's own row.
I can use the df.explode()
. but it only accepts one column. However, I want the pair of the two columns to be 'exploded'. If I do df.explode('col2')
and then df.explode('col3')
, it results it 9 rows instead of 3.
Original DF
col0 col1 col2 col3
1 aa [1,2,3] [1.1,2.2,3.3]
2 bb [4,5,6] [4.4,5.5,6.6]
3 cc [7,8,9] [7.7,8.8,9.9]
3 cc [7,8,9] [7.7,8.8,9.9]
End DataFrame
id col1 col2 col3
1 aa 1 1.1
1 aa 2 2.2
1 aa 3 3.3
2 bb 4 4.4
2 bb 5 5.5
2 bb 6 6.6
3 cc ... ...
Update None of the column have unique values, so can't be used as index.