I am trying to calculate a discount that I would like to apply to each row of two columns of my dataframe and add the result to a new column.
I have already tried many ways, by following existing examples, but everytime an error occurs.
I define the function as:
def delta_perc(x,y):
if y == 0:
return 0
else:
return (x-y)/x*100
and then try to apply the function to my dataframe
ordini["discount"] = ordini.apply(delta_perc(ordini["revenue1"],ordini["revenue2"]), axis=1)
I expected a new column where each row was the result of the function applied to ordini["revenue1"] and ordini["revenue2"].
But I get the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I also tried to apply all the suggestion from here but everytime an error occured.