Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

for Loop over a list fuzzy match printing out match score thanks in advance

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'])

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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'])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading