I'm trying create a new dataframe column that is a partial string match from another dataframe. How would I do the example below?
df1:
# id
1 666666
2 666667
3 666668
4 666667
df2
# ref
1 ref_666666_blah blah
2 ref_666667_blah blah
3 ref_666668_blah blah
4 ref_666667_blah blah
df3 #what I want
# id match
1 666666 ref_666666_blah blah
2 666667 ref_666667_blah blah
3 666668 ref_666668_blah blah
4 666667 ref_666667_blah blah
I know this is not the code but I'm trying to do the below:
df1['match'] = df2['ref'].map(lambda x: x if x.str.contains(df1['match'])
Thanks!