0

I have a Pandas Data frame that let say col3 has a list, I need to convert each item of the list into a new row as follow:

I think I need to transpose on col1 and col2 but not sure.

# the data frame that I have:  
pd.DataFrame({"col1" : [1,2,3],
               "col2" : ['x','y','z'],
               "col3" : [['a', 'b'],['c','d','e'],['f']] })


# the output I'm expecting:
pd.DataFrame({'Sample':[1,1,2,2,2,3],
          "col2" : ['x','x', 'y','y', 'y', 'z'],
          'targets':['a', 'b','c','d','e','f']})
st1980
  • 1
  • 1
  • 2

0 Answers0