我有两个数据帧有一个共同的密钥产品名称,我想做的是创建第三个数据帧,根据部分字符串匹配与80-90%的相似性,数据集相当大,我曾尝试使用tfidf
from{
示例-
import pandas as pd
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]})
df2=pd.DataFrame({'Product_Name2': ['Mini Wireless Sports Stereo Headset', 'VR Box 3D Smart Glass With Remote Controller', 'OnePlus 6 1Sandstone Protective Case'], 'Price2': [40000, 50000, 42000]})
df1set=df1.set_index('Product_Name1')
df2set=df2.set_index('Product_Name2')
df3=df1set.join(df2set,how='inner')
df3
df1
df2
你需要的是模糊匹配。模糊匹配用于比较彼此非常相似的字符串。您可以使用
fuzzy wuzzy
进行此操作。在模糊匹配实例
此值与95%匹配。在
我把df2的顺序改为演示。在
^{pr2}$现在我们编写一个函数,它将
df1 Product_Name1
的每个值与df2 Product_Name2
的每个值相匹配,并返回df2的索引,其中它与最高值匹配。在我们使用apply得到结果
因为我没有你期望的输出,所以我要合并它们。在
如果对你有用,请告诉我
相关问题 更多 >
编程相关推荐