I have a dataframe with a column containing lists, I am trying to iterate over each row in the dataframe and concatenate with each element of the list for that row. I am trying to write code to achieve the result displayed in 'molecule_species'. Any thoughts on this would be appreciated.
Dataframe =
import pandas as pd
df = pd.DataFrame({'molecule': ['a',
'b',
'c',
'd',
'e'],
'species' : [['dog'],
['horse','pig'],
['cat', 'dog'],
['cat','horse','pig'],
['chicken','pig']]})
New column I am trying to create by iterating over rows and list elements, concatenating 'molecule' with each element in the list contained in 'species'.
df['molecule_species'] = [['a dog'],
['b horse','b pig'],
['c cat', 'c dog'],
['d cat','d horse','d pig'],
['e chicken','e pig']]