-2
    c1                c2                             c3
0   [1, 2]     [[a, b], [c, d, e]]      [[aff , bgg], [cff, ddd, edd]]

I want the output to be like :

    c1   c2   c3
0   1    a    aff
1   1    b    bgg 
2   2    c    cff
3   2    d    ddd
4   2    e    edd
Scott Boston
  • 133,446
  • 13
  • 126
  • 161

1 Answers1

2

You can use np.repeat() and chain.from_iterable():

df = pd.DataFrame({'c1': np.repeat(df['c1'].values[0], [len(x) for x in (chain.from_iterable(df['c2']))]),
    'c2': list(chain.from_iterable(chain.from_iterable(df['c2']))),
    'c3': list(chain.from_iterable(chain.from_iterable(df['c3'])))
    })

Returns:

   c1 c2   c3
0   1  a  aff
1   1  b  bgg
2   2  c  cff
3   2  d  ddd
4   2  e  edd

Keep in mind that this is relatively specific to your use case. It assumes that your c2 and c3 columns are instantiated with the same shape.

rahlf23
  • 8,613
  • 3
  • 19
  • 49