【发布时间】:2021-04-28 14:45:00
【问题描述】:
假设我有一个如下所示的 pandas 数据框:
ID String1 String2
1 The big black wolf The small wolf
2 Close the door on way out door the Close
3 where's the money where is the money
4 123 further out out further
我想在 String1 和 String2 列中的每一行交叉制表,然后再进行模糊字符串匹配,类似于Python fuzzy string matching as correlation style table/matrix。
我的挑战是,我发布的链接中的解决方案仅在 String1 和 String2 中的单词数相同时才有效。其次,该解决方案查看列中的所有行,而我希望我的只是逐行比较。
建议的解决方案应该对第 1 行进行类似矩阵的比较:
string1 The big black wolf Maximum
string2
The 100 0 0 0 100
small 0 0 0 0 0
wolf 0 0 0 100 100
ID String1 String2 Matching_Average
1 The big black wolf The small wolf 66.67
2 Close the door on way out door the Close
3 where's the money where is the money
4 123 further out out further
其中匹配平均值是“最大”列的总和除以 String2 中的单词数
【问题讨论】:
-
其中匹配平均值是“最大”列的总和除以 String1 中的单词数 - 你的意思是 String2 而不是 String1?
-
这是正确的@anky,现在将编辑。
标签: python-3.x pandas matrix fuzzy