I have the following df:
quantity#1 unit price#1 line amount#1 line amount#2 line amount#3 line amount#4 VAT
-- ------------ -------------- --------------- --------------- --------------- --------------- -----
0 nan nan 5 nan nan nan 1.05
2 1 1150.5 10 20 30 nan 6.6
6 1 2458 2458 nan nan nan 0
13 1 1689 10 20 30 nan 5.4
17 1 260 260 30 100 75 73.05
From this DF, I want to extract the tax rate from each specific line rates. The tax rate line items should be calculated dynamically so that each line amount times a certain tax rate totals the VAT amount. The tax rates can be 0.09, 0.21 and 0.00 and should be equal to the VAT (BTW) subset. I've tried the following:
x = [0.09, 0.21, 0.00]
for i,row in df.iterrows():
if row['Document Type'] == 0:
df['line amount'[i]] * x == df['BTW']
however this does not work..
Desired output:
quantity#1 unit price#1 line amount#1 line amount#2 line amount#3 line amount#4 VAT
-- ------------ -------------- --------------- --------------- --------------- --------------- -----
0 nan nan 5 nan nan nan 1.05
2 1 1150.5 10 20 30 nan 6.6
6 1 2458 2458 nan nan nan 0
13 1 1689 10 20 30 nan 5.4
17 1 260 260 30 100 75 73.05
#new columns
taxrate#1 taxrate#2 taxrate#3 taxrate #4
-- ------------ -------------- --------------- ---------------
0 0.21 nan nan nan
2 0.21 0.09 0.09 nan
6 0.00 nan nan nan
13 0.09 0.09 0.09 nan
17 0.21 0.09 0.09 0.09
Please help!