0

Consider this dataframe called df_b

c1 c2 c3 c4
0 [1, 2, 3] [4, 5, 6] [7, 8, 9] [10, 11, 12]
1 [13] [14] [15] [16]

Each row may contain different length lists, however the length for a single row must be the same for each column. I am trying to unroll the dataframe, but not using explode which creates all combinations. Instead the output I am looking for is:

c1 c2 c3 c4
0 1 4 7 10
1 2 5 8 11
2 3 6 9 12
3 13 14 15 16

where the first row would result in 3 rows being generated (length of list is 3) and the second row would result in 1 row being generated (length of list is 1). Is there a single pandas function which would do this or would this require a combination of operations?

0 Answers0