4

I have been recycling a bunch of code from all over the place to create a string matcher for two csv files I have.

The output of my Code right now is the 3 highest matches per string. I want to additionally include cutoff below a certain match score. So that only matches above that score are shown. I thought this would be easy as according to the documentation I can just include the score_cutoff parameter into the process.extract function, but for some reason this is not an acceptable input.

Here is the code I have right now:

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)
Tim
  • 161
  • 7
  • 24

1 Answers1

4

I don't see "score_cutoff" as a parameter in process.extract(), but I think you can do something like

process.extractBests(x,master_names,limit=limit,score_cutoff=cutoff)
Andy M
  • 141
  • 3