I am doing some fuzzy matching on addresses and am filtering on a high score. IF that score exists in my data set then I want to call another function that looks at the data and checks to see if there are sales/calls associated with it.
I want to ultimately return a list of values that fit the criteria in that function. While debugging I can see The "sales_and_calls_test" function works. I see the values getting appended to my lists, however, when I go to the next iteration I see my lists in my debug watch change from a value to a "Name Error: name "call_list sales_list" not defined
Can someone please look over my syntax and show me what Im missing? Thanks!
Here's my code:
def sales_and_calls_test(v_sales, v_calls):
calls_list = []
sales_list = []
if v_sales > 1:
print(v_sales, v._1)
sales_list.append(v_sales)
if v_calls > 1:
print(v_calls, v._1)
calls_list.append(v_calls)
return calls_list, sales_list
for v in match_table.itertuples():
#print(v)
if not string_len_test(l.Address_1, v.Address_2):
lev_score = lev(l.Address_1, v.Address_2)
fuzz_score = fuzz.token_sort_ratio(l.Address_1, v.Address_2)
if fuzz_score >= 90:
sales_and_calls_test(v._6, v._7)
#print(lev_score, fuzz_score)
else:
if fuzz_score == 87:
print('close', v.Address, l.Address_2, v._1, v._6, v._7, v._8)
print(lev_score, fuzz_score)
else:
continue
##*** side note does anyone know why after I perform itertuples()
## that some of my column's change from their names to _number?
CodePudding user response:
I figured it out. I had to make my first function return a true/false.
Then I realized that I needed to do a better job comparing the different strings, length was too generic. Instead I opted with using Jaro distance.
I set a condition for the distance and then if that condition as met I returned a value "True"
That reduced my data by a lot! then I called the "sales_and_calls_test" function and I updated the return values to return the list and if it doesnt fit the criteria then pass (which reduced my data even more!)
Here's my updates:
def sales_and_calls_test(v_sales, v_calls):
if v_sales > 1:
sales_list.append(v_sales)
return sales_list
elif v_calls > 1:
calls_list.append(v_calls)
return calls_list
else:
pass
for v in match_table.itertuples():
#print(v)
if string_len_test(l.Address_1, v.Address_2) == True:
lev_score = lev(l.Address_1, v.Address_2)
fuzz_score = fuzz.token_sort_ratio(l.Address_1, v.Address_2)
if fuzz_score >= 90:
sales_and_calls_test(v._6, v._7)
#print(lev_score, fuzz_score)
else:
if fuzz_score == 87:
print('close', v.Address, l.Address_2, v._1, v._6, v._7, v._8)
print(lev_score, fuzz_score)
else:
continue