首页 > 解决方案 > fuzzywuzzy match in python with if condition

问题描述

i have two set of data were i need to find the similar matches using fuzzywuzzy or any other options,

Data set contains the column as below mentioned(Columns are same in the both the Data set but rows differ)

SLNo|Product Name|Brand

first i need to find the brand similarity if the brand similarity is greater than 95 then i need to check the product name similarity

i have tried below Code

import pandas as pd
from fuzzywuzzy import process, fuzz

Bl=pd.read_excel(r'C:\Datas\BLRL3.xlsx')
master=pd.read_excel(r'C:\Datas\MO.xlsx')

actual_Name= []
similarity = []
brandsimilarity = []

for i in Bl.Productname:
        for j in Bl.Brand:
                brandratio = process.extract( i, master.Brand, limit=1,scorer=fuzz.token_sort_ratio)
                brandsimilarity.append(brandratio[0][1])
                if brandsimilarity > 95:
                        ratio = process.extract( i, master.Productname, limit=1,scorer=fuzz.token_sort_ratio)
                        actual_Productname.append(ratio[0][0])
                        similarity.append(ratio[0][1])


Bl['actual_Name'] = pd.Series(actual_Name)
Bl['similarity'] = pd.Series(similarity)
Bl['brandsimilarity']=pd.Series(brandsimilarity)

Bl.to_csv("oput2503-2.csv",index = False)

Error: if brandsimilarity > 95: TypeError: '>' not supported between instances of 'list' and 'int'

标签: pythonpandasfuzzywuzzy

解决方案


作为错误状态,将列表与整数进行比较是一个 TypeError。为了达到你想要的,你不应该使用

brandsimilarity.append(brandratio[0][1])

brandsimilarity = brandratio[0][1]

推荐阅读