1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊
SequenceMatcher
不是為熊貓系列設(shè)計(jì)的。你可以
.apply
的功能。SequenceMatcher
例子偶數(shù)空格
isjunk=None
不被認(rèn)為是垃圾。With
isjunk=lambda y: y == " "
將空格視為垃圾。
from difflib import SequenceMatcher
import pandas as pd
data = {'Text1': ['Performance results achieved by the approaches submitted to this Challenge.', 'Accuracy is one of the basic principles of perfectionist.'],
? ? ? ? 'All': ['The six top approaches and three others outperform the strong baseline.', 'Where am I?']}
df = pd.DataFrame(data)
# isjunk=lambda y: y == " "
df['ratio'] = df[['Text1', 'All']].apply(lambda x: SequenceMatcher(lambda y: y == " ", x[0], x[1]).ratio(), axis=1)
# display(df)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Text1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? All? ? ?ratio
0? Performance results achieved by the approaches submitted to this Challenge.? The six top approaches and three others outperform the strong baseline.? 0.356164
1? ? ? ? ? ? ? ? ? ? Accuracy is one of the basic principles of perfectionist.? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Where am I?? 0.088235
# isjunk=None
df['ratio'] = df[['Text1', 'All']].apply(lambda x: SequenceMatcher(None, x[0], x[1]).ratio(), axis=1)
# display(df)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Text1? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? All? ? ?ratio
0? Performance results achieved by the approaches submitted to this Challenge.? The six top approaches and three others outperform the strong baseline.? 0.410959
1? ? ? ? ? ? ? ? ? ? Accuracy is one of the basic principles of perfectionist.? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Where am I?? 0.117647
添加回答
舉報(bào)