0

My dataframe looks like following:

col1   col2 
1      [1,2,3]
2      [1,2]
3      [1]

I want to exapnd the dataframe on the basis of col2 such that the values of other columns gets copied in the new rows as following.

col1    col2
1        1
1        2
1        3
2        1
2        2
3        1

I've scoured prior questions for something to get me started, but no luck. Any help is appreciated.

Prince Bhatti
  • 4,671
  • 4
  • 18
  • 24
  • 1
    This has been asked before... with a little modification you can use anything in https://stackoverflow.com/questions/48197234/explode-stack-a-series-of-strings. – cs95 Jan 28 '18 at 07:59
  • 1
    If you're using my solution, use `np.concatenate(df.col2.tolist())` to unwrap the elements. – cs95 Jan 28 '18 at 08:05

0 Answers0