for Loop over a list fuzzy match printing out match score

Question:

I have a question about a fuzzy match.

Here is the function I am trying to write:

def fuzz(x, keys):
    for i in keys:
        a = fuzz.ratio(x, keys)
    return

dataset['match'] = dataset.col1.apply(fuzz, word=['apple', 'orange', 'banana'])

How do I use a for loop (or other solution) over a list and append matching scores to dataset?

Expected output:

col1    match
banana  100
appl     80
oranges  90
ba       20
.
.
.
.

tried to for loop on a list

Asked By: james

||

Answers:

import fuzzywuzzy
from fuzzywuzzy import fuzz

def fuzz_match(x, keys):
  ratios = []
  for i in keys:
    a = fuzz.ratio(x, i)
    ratios.append(a)
  return max(ratios)

dataset['match'] = dataset.col1.apply(fuzz_match, keys=['apple', 'orange', 'banana'])
Answered By: Pingu
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.