I would like to use the apply and lambda methods in python in order to change the pricing in a column. The column name is Price. So, if the price is less than 20 I would like to pass and keep it the same. If 30>price>20 I would like to add 1. If the price is 40>price>30 then I would like to add 1.50. And so on. I am trying to figure out a way to apply these functions over a column and then send it back to an excel format in order to updating the pricing. I am confused as to how to do so. I have tried putting this operation in a function using an if clause but it is not spitting out the results that I would need to (k is the name of the dataframe):
def addition():
if k[k['Price']] < 20]:
pass
if k[(k['Price']] > 20) & (k['Price] < 30)]:
return k + 1
if k[(k['Price']] > 30.01) & (k['Price] < 40)]:
return k + 1.50
and so on. However, at the end, when I attempt to send out (what I thought was the newly updated k[k['Price] format in xlsx it doesn't even show up. I have tried to make the xlsx variable global as well but still no luck. I think it is simpler to use the lambda function, but I am having trouble deciding on how to separate and update the prices in that column based off the conditions. Much help would be appreciated.
This is the dataframe that I am trying to perform the different functions on:
0 23.198824
1 21.080706
2 15.810118
3 21.787059
4 18.821882
...
33525 20.347059
33526 25.665882
33527 33.077647
33528 21.803529
33529 23.043529
Name: Price, Length: 33530, dtype: float64