0

I have a dataframe with the below format:

         A              B              C
0  [[1,2],[3,4]]  [[5,6],[7,8]]  [[9,10],[11,12]]

for multiple rows.
The sub lists are always of length 2 and the length of A,B,C lists are always the same size.However the lengths of the latter vary and for example can be of size 2 or 6..etc for different rows.

What i would like to do is to explode rows like these into:

         A              B              C
0      [1,2]          [5,6]          [9,10]
0      [3,4]          [7,8]          [11,12]
mozway
  • 194,879
  • 13
  • 39
  • 75
Epitheoritis 32
  • 366
  • 5
  • 13

1 Answers1

2

Assuming you really have lists of lists, a simple explode on all columns should work:

df.explode(df.columns.to_list())

output:

        A       B         C
0  [1, 2]  [5, 6]   [9, 10]
0  [3, 4]  [7, 8]  [11, 12]

used input:

df = pd.DataFrame([[[[1,2],[3,4]], [[5,6],[7,8]], [[9,10],[11,12]]]],
                  columns=['A', 'B', 'C'])
mozway
  • 194,879
  • 13
  • 39
  • 75