1

I have a dataframe:

df = 
A  B  C
1 [2,3] [4,5]

And I want to explode it element-wise based on [B,C] to get:

df = 
A B  C
1 2  4
1 3  5

What is the best way to do so? B and C are always at the same length.

Thanks

Cranjis
  • 1,590
  • 8
  • 31
  • 64
  • this has been solved multiple times. Check [here](https://stackoverflow.com/questions/53218931/how-to-unnest-explode-a-column-in-a-pandas-dataframe-into-multiple-rows/61390677#61390677) – Onyambu May 16 '22 at 18:30

1 Answers1

1

Try, in pandas 1.3.2:

df.explode(['B', 'C'])

Output:

   A  B  C
0  1  2  4
0  1  3  5
Scott Boston
  • 147,308
  • 15
  • 139
  • 187