I have two columns from two pandas dataframes with measurement data that I'd like to align by substring matching. More precisely if the string in df1[col1] is a substring of df2[col2] i want to merge the tables.
My very naive approach:
for string in df1['col1']:
df1['match'] = df2['col2'].str.contains(string, regex=False, case=False)
How can i approach the task in a more efficient way?
I found this post about filtering by substring criteria that uses an or-chained regex pattern to filter, but if I'm not mistaken this does not yield the information that I would need to align the columns:
df.apply(lambda col: col.str.contains('foo|bar', na=False), axis=1)