I have two dataframes:
mapping = pd.DataFrame({'idx': ['a','b','c'], 'val': [1, 2, 3]})
obs = pd.DataFrame({'obs': ['a','c','a','a','b','d']})
I would like for all observations in obs, that are present in mappings idx column, to get the value of mappings val column. If the value does not exist in mappings idx column, it should be discarded.
That is, I would like to end up with the following dataframe:
obs_mapped = pd.DataFrame({'obs': [1,3,1,1,2]})
Is there a handy way to do this with pandas?