What you need is fuzzy matching. Fuzzy matching is used to compare strings which are very similar to each other. You can use fuzzy wuzzy
for this.
Example of fuzzy matching
from fuzzywuzzy import process
process.extractOne('Mini Wireless Bluetooth Sports Stereo Headset', df2.Product_Name2)
('Mini Wireless Sports Stereo Headset', 95, 0)
This value has a 95% match.
I have changed the order of df2 for demonstration.
df1=pd.DataFrame({'Product_Name1': ['Mini Wireless Bluetooth Sports Stereo Headset',
'VR Box 3D Smart Glass With Remote Controller',
'OnePlus 6 Sandstone Protective Case'],
'Price1': [40000, 50000, 42000]})
df1
Product_Name1 Price1
0 Mini Wireless Bluetooth Sports Stereo Headset 40000
1 VR Box 3D Smart Glass With Remote Controller 50000
2 OnePlus 6 Sandstone Protective Case 42000
df2=pd.DataFrame({'Product_Name2': ['Mini Wireless Sports Stereo Headset',
'OnePlus 6 1Sandstone Protective Case',
'VR Box 3D Smart Glass With Remote Controller'],
'Price2': [40000, 42000, 50000]})
df2
Product_Name2 Price2
0 Mini Wireless Sports Stereo Headset 40000
1 OnePlus 6 1Sandstone Protective Case 42000
2 VR Box 3D Smart Glass With Remote Controller 50000
Now we write a function which matches each value of df1 Product_Name1
with every value of df2 Product_Name2
and return the index of df2 where it matched the highest.
def fuzzy(x):
closest_match = process.extractOne(x, df2.Product_Name2.values)[0]
index = pd.Index(df2.Product_Name2).get_loc(closest_match)
return index
The we use apply to get the result
df1['match'] = df1['Product_Name1'].apply(fuzzy)
df1
Product_Name1 Price1 match
0 Mini Wireless Bluetooth Sports Stereo Headset 40000 0
1 VR Box 3D Smart Glass With Remote Controller 50000 2
2 OnePlus 6 Sandstone Protective Case 42000 1
As I don't have your expected output, I'm gonna merge them.
pd.merge(df1, df2, left_on='match', right_on=df2.index)
Product_Name1 Price1 match Product_Name2 Price 2
0 Mini Wireless Bluetooth Sports Stereo Headset 40000 0 Mini Wireless Sports Stereo Headset 40000
1 VR Box 3D Smart Glass With Remote Controller 50000 2 VR Box 3D Smart Glass With Remote Controller 50000
2 OnePlus 6 Sandstone Protective Case 42000 1 OnePlus 6 1Sandstone Protective Case 42000
Let me know if it works for you