I want to merge 2 dataframes on string columns with values containing wildcards as we can do with like in SQL.
Example :
import pandas as pd
df1 = pd.DataFrame({'A': ["He eat an apple in his office.", "There are many apples on the tree."], 'B': [1, 2]})
df2 = pd.DataFrame({'A': ["apple*tree", "apple*pie"], 'C': [4, 9]})
df1
A B
0 He eat an apple in his office. 1
1 There are many apples on the tree. 2
df2
A C
0 apple*tree 4
1 apple*pie 9
pd.merge(df1, df2, on = ['A'])
# What it gives me :
Empty DataFrame
Columns: [A, B, C]
Index: []
# What I want:
A B C
0 There are many apples on the tree. 2 4
I want to join the two dataframes and "apple*tree" of df2 has to match the sentence "There are many apples on the tree." of df1.
Can you help me to do this please?
I have found the function fnmatch.fnmatch(string, pattern) but can I use it in this case with a merge?