question about a fuzzy match.
Here is function 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 to 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
.
.
.
.
thanks in advance!
tried to for loop on a list
>Solution :
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'])