I have a list of values. How can I replace all values in a Dataframe column not in the given list of values?
For example,
>>> df = pd.DataFrame(['D','ND','D','garbage'], columns=['S'])
>>> df
S
0 D
1 ND
2 D
3 garbage
>>> allowed_vals = ['D','ND']
I want to replace all values in the column S of the dataframe which are not in the list allowed_vals with 'None'. How can I do that?