I am looking to execute the script only when it satisfies the condition.
If Column1 is not blank then only we can use the below script else will print the message. I have tried several ways but couldn't find the possible way to work.
Sheet1
id_number company_name match_acc
IN2231D AXN pvt Ltd
UK654IN Aviva Intl Ltd
Ship Incorporations
LK0678G Oppo Mobiles pvt ltd
NG5678J Nokia Inc
Sheet2
identity_no Pincode company_name
IN2231 110030 AXN pvt Ltd
UK654IN 897653 Aviva Intl Ltd
SL1432 07658 Ship Incorporations
LK0678G 120988 Oppo Mobiles Pvt Ltd
Script i have been using
df1 = pd.read_excel(open(r'input.xlsx', 'rb'), sheet_name='sheet1')
df2 = pd.read_excel(open(r'input.xlsx', 'rb'), sheet_name='sheet2')
if df1[['id_number']] is not NaN:
cross = df1[['id_number']].merge(df2[['identity_no']], how='cross')
cross['match_acc'] = cross.apply(lambda x: fuzz.ratio(x.id_number, x.identity_no), axis=1)
df1['match_acc'] = df1.id_number.map(cross.groupby('id_number').match_acc.max())
How we can execute it if i try using it within a function :
def word(x,y):
cross = df1[['id_number']].merge(df2[['identity_no']], how='cross')
cross['match_acc'] = cross.apply(lambda x: fuzz.ratio(x.id_number, y.identity_no), axis=1)
df1.id_number.map(cross.groupby('id_number').match_acc.max())
df['match_acc'] = df1.apply(lambda x:word if (x['id_number'] == 'NaN') else 'No',1)
Please suggest