I am looking to find and separate taxable values from the total value using an conditional statement.
If first 2 characters from column Tax_no1 and Tax_no2 are different then we have to calculate the Tax percentage 18% from the Amount column and update the value in value3 column
Value3 = Amount*18/100
If first 2 characters from column Tax_no1 and Tax_no2 are same then we have to calculate the Tax percentage 18% from the Amount column divide the calculated value by 2 and update the values in value1 and value2 column
value1 = (Amount * 18/100)/2, value1 = (Amount * 18/100)/2
OR
value1 = Amount * 9/100 , value2 = Amount * 9/100
Input Data :
Tax_no1 Tax_No2 Amount value1 value2 value3
AZ0001B AZ0001B 35000
BZ0002A CD0002A 12800.00
25CA895 25CA895 28967.90
NY78615 DY78615 367899.9
LO10985 LO10985 156789
01256NY 02256NY 2890657
Expected Output Value:
Tax_no1 Tax_No2 Amount value1 value2 value3
AZ0001B AZ0001B 35000 3150 3150 NaN
BZ0002A CD0002A 12800.00 NaN NaN 2304
25CA895 25CA895 28967.90 2607.11 2607.11 NaN
NY78615 DY78615 367899.9 NaN NaN 66221.98
LO10985 LO10985 156789 14111.01 14111.01 NaN
01256NY 02256NY 2890657 NaN NaN 520318.26
Script I have tried to use :
df['Tax1'] = df['Tax_no1'].str[:2]
df['Tax2'] = df['Tax_no2'].str[:2]
if df['Tax1'] != df['Tax2']:
df['value3'] = Amount * 18/100
else:
df['value1'] = Amount * 9/100
df['value2'] = Amount * 9/100