0

Here is my code: I have three conditions profit, loss and discount

if  df['Condition'] == "Profit":
        df["price"]= df["costprice"]- 1.5*df["sp"]
elif df['Condition'] == "Loss":
        df["price"]= df["costprice"]- 1.5*df["sp"]             
else:
      df["price"]= df["targetprice"]-1.5*df["sp"]

1 Answers1

1

Try this apply call instead:

def func(x):
    if  x[1] == "Profit":
            x[2]= x[3]- 1.5*x[4]
    elif x[1] == "Loss":
            x[2]= x[3]- 1.5*x[4]             
    else:
          x[2]= x[5]-1.5*x[4]
df = df.apply(func)
print(df)
U12-Forward
  • 65,118
  • 12
  • 70
  • 89