python - 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'
解决方案
作为错误状态,将列表与整数进行比较是一个 TypeError。为了达到你想要的,你不应该使用
brandsimilarity.append(brandratio[0][1])
但
brandsimilarity = brandratio[0][1]
推荐阅读
- annotations - Mask R-CNN 中的边界框大小 - 太短
- css - 访问 SVG 图像 Flutter 中的组件
- amazon-web-services - AWS Step 函数参数没有移动到下一步
- racket - DrRacket 中参考悬停时图形问号的含义?
- flutter - 如何修复 RenderBox 未在 ListTile 中列出?
- verilog - Verilog 中未解决的对“fulladder”的引用
- c# - 同一张表的多对多关系。英孚
- mysql - 通过(选择结果)mysql更新行
- javascript - JavaScript Click-Event 触发器每次点击触发多次
- java - 为什么 UriComponentsBuilder 忽略空查询参数?