I am trying to change the price of some of the items based on the country and the product string.
I have the table below.
country product price
Us blue good apple 9
US red bad Apple 10
Us blue bad apple 12
Canada blue excel apple 8
Canada yellow good Mango 15
Mexico orange bad Orange 16
Costa yellow med Orange 15
Brazil red good Orange 19
Brazil blue bad apple 9
Guatemala purple meh Pear 32
Guatemala green sweet Melon 4
Honduras grade 2 orange 5
From this table, if the price of fruits that has strings "blue" and "apple" but not from "Canada" is less than 11 then I would like to set the price of those to 11. So the result of those conditions would be. (the price of two rows are changed)
country product price
Us blue good apple 11
US red bad Apple 10
Us blue bad apple 12
Canada blue excel apple 8
Canada yellow good Mango 15
Mexico orange bad Orange 16
Costa yellow med Orange 15
Brazil red good Orange 19
Brazil blue bad apple 11
Guatemala purple meh Pear 32
Guatemala green sweet Melon 4
Honduras grade 2 orange 5
I have tried
df.loc[((df['product'].str.lower().str.contains('apple')) &
(~df['country'].str.lower().str.contains('canada')) &
(~df['product'].str.lower().str.contains('red'))), 'Price'] = 11
But I am not sure how to compare the price and change those specific products. I tried multiple things but all don't seem to work.
(changing and breaking up the product name into a different column is not an option for me)
& (df.Price < 11)to your example to select the prices that you want to set to 11?