0

I use the following simple code to calculate the fuzz.ratio() value of values of two lists and get the error : TypeError: object of type 'float' has no len(). (on the line : if (fuzz.ratio(i, j) >= 85): ) The code is below:

from fuzzywuzzy import fuzz 
from fuzzywuzzy import process 
import pandas as pd


mra = pd.read_excel(r"C:\Users\gpmammadova\MRA_REPORT.xlsx")

cru = pd.read_excel(r"C:\Users\gpmammadova\CRU SME pipeline.xlsx")

cust_mra = mra['CUSTOMERNAME']

cust_cru = cru['Name of Client']

s_mra = cust_mra.tolist()

s_cru = cust_cru.tolist()

matched_cru = []

for i in s_mra:
    for j in s_cru:
        if (fuzz.ratio(i, j) >= 85):
            matched_cru.append(j)
        else:
            matched_cru.append('NOT FOUND')
gunel
  • 161
  • 13
  • 1
    One of i and j (or both) is a float. Maybe NaN? Try `cust_mra = mra['CUSTOMERNAME'].fillna("")` and same for cru. – Alex Hall Nov 29 '19 at 06:12

1 Answers1

1

Try forcing your input to be string type:

mra = pd.read_excel(r"C:\Users\gpmammadova\MRA_REPORT.xlsx", dtype=str)
cru = pd.read_excel(r"C:\Users\gpmammadova\CRU SME pipeline.xlsx", dtype=str)
jeremy_rutman
  • 3,552
  • 4
  • 28
  • 47