1 回答
TA贡献1828条经验 获得超6个赞
SequenceMatcher
不是为熊猫系列设计的。你可以
.apply
的功能。SequenceMatcher
例子偶数空格
isjunk=None
不被认为是垃圾。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
添加回答
举报