1

So I am fuzzy matching two dataframes and want to find a match from the right table if it has a score of over 80. So for the ones that do not find a match over 80 it ends up with Nonetype which causes the script to fail. How can I handle this? I still want to know if it didn't find a match, so if I can display it as "None" or just blank I would prefer that.

str2Match['key'] = str2Match.apply.(lambda x: process.extractOne(x['PRODUCT_NAME'], strOptions['REFERENCE_NAME'], score_cutoff=80)[0], axis=1)
Cole
  • 99
  • 10

2 Answers2

1

Okay, so I got this working by just using a custom function like @pavan-chandaka suggested and put a try in it. For whatever reason, extractOne from fuzzywuzzy just breaks if it can't find a match, so I'm basically just passing the None value down to my dataframe with the try.

 def namematch(pname, rname):
    try:
        match = (process.extractOne(pname, rname, score_cutoff=80)[0])
        return match
    except:
        return None
Cole
  • 99
  • 10
0

Take a look if this way of doing works.

From lambda call a custom function. Some what like

lambda x : customfunc(YOUR ARGUMENTS)

Inside the custom function call extractOne. As the extractOne returns None, when value not found, based on the return value polish the return for 'None' in the way you want.

def customfunc(YOUR ARGUMENTS):
    ret = process.extractOne(ARGUMENTS)
    if ret is None:
         #RETURN SOMETHING, YOU CAN MEAN NO VALUE.
    else:
         #RETURN THE VALUE.
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34
  • Are you returning a dummy tuple from the custom function for None? – Pavan Chandaka Jun 25 '20 at 03:56
  • It is actually breaking on the ret = process.extractOne(ARGUMENTS) portion. So it seems like that function just is not able to have a value of None for some reason. – Cole Jun 25 '20 at 14:26
  • I was able to get it working by using a try instead of the if. However, it now just skips the rows with None and does not actually merge them in the dataframe at this point. So I have a new issue to figure out. – Cole Jun 25 '20 at 14:34