IF 语句在 continue 语句后不调用我的数据
IF statements not calling my data after continue statement
当我 运行 下面的代码时,我得到了一堆说“没有结果”的行
我想通过 string_len_test
函数查看地址是否相似,如果不相似则对每个地址进行某种模糊匹配。如果每次比较的结果都是某个值 % value 那么我想对它们执行一些逻辑(现在我只有打印语句)。我知道我的数据具有很高的匹配分数,但他们似乎在此 if/else 语句中被跳过了。
def string_len_test(l_value, v_value):
if abs(len(l_value) - len(v_value)) >2:
#print('not matched')
return False
elif abs(len(l_value) - len(v_value)) == 0:
#print('potential match', l_value, v_value)
return True
else:
return False
for link in Address1.itertuples():
if link._5 == 'X':
match_table = Adddress_main_X
else:
match_table = Adddress_main_Y
for v in match_table.itertuples():
if not string_len_test(link.Address_1, v.Address_2):
continue
lev_score = lev(link.Address_1, v.Address2)
fuzz_score = fuzz.token_sort_ratio(link.Address_1, v.Address2)
#print(lev_score)
#print(fuzz_score)
if lev_score >=98 | fuzz_score >90:
print('match', link.Address_1, v.Address2)
if lev_score >= 80:
print('close', link.Address_1, v.Address2)
else:
print('no results')
添加了 else pass 语句并去掉了 continue 语句。谢谢大家的帮助!
当我 运行 下面的代码时,我得到了一堆说“没有结果”的行
我想通过 string_len_test
函数查看地址是否相似,如果不相似则对每个地址进行某种模糊匹配。如果每次比较的结果都是某个值 % value 那么我想对它们执行一些逻辑(现在我只有打印语句)。我知道我的数据具有很高的匹配分数,但他们似乎在此 if/else 语句中被跳过了。
def string_len_test(l_value, v_value):
if abs(len(l_value) - len(v_value)) >2:
#print('not matched')
return False
elif abs(len(l_value) - len(v_value)) == 0:
#print('potential match', l_value, v_value)
return True
else:
return False
for link in Address1.itertuples():
if link._5 == 'X':
match_table = Adddress_main_X
else:
match_table = Adddress_main_Y
for v in match_table.itertuples():
if not string_len_test(link.Address_1, v.Address_2):
continue
lev_score = lev(link.Address_1, v.Address2)
fuzz_score = fuzz.token_sort_ratio(link.Address_1, v.Address2)
#print(lev_score)
#print(fuzz_score)
if lev_score >=98 | fuzz_score >90:
print('match', link.Address_1, v.Address2)
if lev_score >= 80:
print('close', link.Address_1, v.Address2)
else:
print('no results')
添加了 else pass 语句并去掉了 continue 语句。谢谢大家的帮助!