我想看看如何从5条记录中选出“最有可能”的值。我认为fuzzywuzzy
包可能可以工作,但我想知道即使没有提供搜索字符串,这个或另一个包是否也可以工作
我尝试了正则表达式,但认为它根本不起作用,然后遇到了以下fuzzywuzzy
代码:
https://www.datacamp.com/community/tutorials/fuzzy-string-python
from fuzzywuzzy import process
str2Match = "apple inc"
strOptions = ["Apple Inc.","apple park","apple incorporated","iphone"]
Ratios = process.extract(str2Match,strOptions)
# You can also select the string with the highest matching percentage
highest = process.extractOne(str2Match,strOptions)
结果是:
>> print (Ratios)
[('Apple Inc.', 100), ('apple incorporated', 90), ('apple park', 67), ('iphone', 30)]
>> print(highest)
('Apple Inc.', 100)
上面的结果是有意义的,因为有一个提供的搜索字符串str2Match
,但我想知道,代码是否有可能自动生成最佳(最高)值(例如,当它意识到'Apple Inc'
和'apple incorporated'
足够相似时,自动生成一些值)?谢谢
目前没有回答
相关问题 更多 >
编程相关推荐