For the two dataframes below, I'm trying to see if name1
in df1
contains name2
in df2
. How to achieve this? I'm thinking of doing a join but there's no join key. Can I specify something like if name2 contains name1 then join them
, and result in the output below? Many thanks for your help
df1:
Name1 Colour
Lisa ('blue','yellow')
Bart ('pink', 'yellow')
Homer ('green', 'black')
Maggie ('yellow','orange','blue')
df2
Name2 Age
Lisa S. 5
Bart Simpsons 8
Bob 10
Ben 30
expected output:
Name2 Age Name1 colour
Lisa S. 5 Lisa ('blue','yellow')
Bart Simpsons 8. Bart ('pink', 'yellow')