I'd like to replace string values within a certain column of a pandas dataframe in python 3 with a particular set of substrings. If the string value in a column contains one of the substrings I have in a separate list(or whatever other data structure that's suitable), then replace the value in the dataframe with that particular substring. If the string value doesn't have any of the selected substrings, then remove it all together from the dataframe.
For example:
Index A B C
0 .... Ottawa ON and Hull ....
1 .... Grand Forks BC ....
2 .... Frank AB ....
3 .... Prairies ....
And I have a list or really any common data structure that holds the following substring values : "ON", "BC", "AB"
My result should look like this:
Index A B C
0 .... ON ....
1 .... BC ....
2 .... AB ....
I can't seem to come up with a clean way of addressing my problem. Any help will be much appreciated. Thank you!