比较一个csv的两列并在另一个csv中输出字符串相似率

比较一个csv的两列并在另一个csv中输出字符串相似率,第1张

比较一个csv的两列并在另一个csv中输出字符串相似率

这是使用以下方法完成此 *** 作的另一种方法

pandas

考虑您的csv数据是这样的:

Column 1,Column 2 tomato,tomatoe potato,potatao apple,appel

import pandas as pdimport difflib as diff#Read the CSVdf = pd.read_csv('datac.csv')#Create a new column 'diff' and get the result of comparision to itdf['diff'] = df.apply(lambda x: diff.SequenceMatcher(None, x[0].strip(), x[1].strip()).ratio(), axis=1) #Save the dataframe to CSV and you could also save it in other formats like excel, html etcdf.to_csv('outdata.csv',index=False)

结果

Column 1,Column 2 ,difftomato,tomatoe ,0.923076923077potato,potatao ,0.923076923077apple,appel ,0.8


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5663141.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存