I am cleaning a dataset and I need to replace the string in column A with "foo" if column B contains one of the strings from a list of options.
I have a list of values contained in column B that I want to use to indicate that I need to replace column A
A B
foo apple
foo banana
bar cherry
foo orange
bar melon
bar papaya
I have multiple values that could trigger a replacement.
list = ['papaya', 'avocado', 'cherry', 'mango']
using that list to inform the replacement I want to change the value in column A to foo if column B contains one of the values in the list. The results in this example would look like this.
A B
foo apple
foo banana
foo cherry
foo orange
bar melon
Any advice helps, thanks.