0

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

okuoub
  • 716
  • 6
  • 19
  • 52
  • 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

0

Try, in pandas 1.3.2:

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

Output:

   A  B  C
0  1  2  4
0  1  3  5
Scott Boston
  • 133,446
  • 13
  • 126
  • 161