如何使用fuzzyfuzzy优化for循环以查找匹配的2字符串

2024-09-26 22:55:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用fuzzywuzzylib得到一个字符串与Python中的另一个字符串相似的概率。你知道吗

目前,我使用for循环进行搜索,搜索非常耗时。你知道吗

以下是工作代码:

from fuzzywuzzy import fuzz

with open('all_nut_data.csv', newline='') as csvfile:
   spamwriter = csv.DictReader(csvfile)
   mostsimilarcs = 0
   mostsimilarns = 0
   for rowdata in spamwriter:
       mostsimilarns = fuzz.ratio(rowdata["Food Item"].lower(), name.lower())
       if mostsimilarns > mostsimilarcs:
           mostsimilarcs = mostsimilarns
           row1 = rowdata

如何在没有for循环的情况下优化代码?你知道吗

注*CSV文件包含600000行和17列


Tags: csvcsvfile字符串代码fromfor概率lower

热门问题