这是使用以下方法完成此 *** 作的另一种方法
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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)