我一直在回收来自各处的一堆代码,为我拥有的两个csv文件创建一个字符串匹配器。
我的代码的输出现在是每个字符串的3个最高匹配。 我还希望在某个匹配分数之下另外包含截止值。这样只会显示高于该分数的匹配。我认为这很容易,因为根据文档我可以将score_cutoff参数包含在process.extract函数中,但由于某种原因,这不是一个可接受的输入。
以下是我现在的代码:
from fuzzywuzzy import process
import pandas as pd
import os
def StringMatch (master, testfile, num_match: object = 3):
master_names = master.iloc[:,3]
test_names = testfile.iloc[:,0]
fhp_new = [process.extract(x, master_names, limit=limit) for x in test_names]
lab=" "
i=1
while i<=num_match:
lab = lab + " " + "Match" + str(i)
i = i+1
aggregated_matches = pd.DataFrame(fhp_new, columns = lab.split())
d={}
for x in range (1, num_match + 1):
d["Match{0}".format(x)] = [y[0] for y in aggregated_matches["Match" + str(x)]]
d["test_original"] = test_names
d["perfect match"] = d["Match1"] == d["test_original"]
out = pd.DataFrame(data=d)
out.to_csv(str(outFile + ".csv"))
return (out)
print ("finished")
master = pd.read_csv("MasterVendorDevice.csv")
testfile = pd.read_csv("testfile.csv", encoding='latin-1')
limit=3
baseDir = os.path.join("/Users", "Tim", "Desktop", "String Matcher")
outDir = os.path.join(baseDir, "out")
if not os.path.exists(outDir):
os.makedirs(outDir)
outFile = os.path.join(outDir, "matches")
StringMatch(master, testfile)
答案 0 :(得分:0)
我没有看到&#34; score_cutoff&#34;作为process.extract()中的参数,但我认为你可以做类似
的事情process.extractBests(x,master_names,limit=limit,score_cutoff=cutoff)