I was wondering if someone would be able to help me with the following. I have this dataframe:
df = {'Price': [60.50,5.20,7,20.16,73.50,12.55,8.70,6,54.10,89.40,12,55.50,6,120,13.20],
'Discount': [1,1,1,0.5,0.4,1,0.3,0.2,1,1,1,1,1,0.1,0.9]}
df = pd.DataFrame(data=df)
What I am trying to do is iterate through each row in the df and if the Discount amount is 1, then populate the Amount off for that row with 0. Otherwise, it would calculate the amount it has been taken off according to the discount. I have the following code to do this:
for index, row in df.iterrows():
if row['Discount'] == 1:
df['Amount off'] = 0
else:
df['Amount off'] = df['Price']*df['Discount']
However, once I run it, it does not produce the correct amount off when the discount is 1. Is anyone able to give me some hints and directions on where I am going wrong please?
Thank you in advance!
discountmeant the same thing across all values, no discount would be0and not1meaning you could just calculatedf['Amount off']=df['Price']*df['Discount']