I have a dataframe containing two columns:
val1 | val2
-------------
1 'dog'
2 'cat'
3 'pig'
4 'crab'
and a dictionary
my_dict = {'dog' : 'Hund', 'pig' : 'Schwein'}
I want to apply the dictionary to val2 just where the values exist in my_dict, otherwise just leave the original ones:
val1 | val2
-------------
1 'Hund'
2 'cat'
3 'Schwein'
4 'crab'
I found similar answers to this question, but in all cases the elements that don't exist in the dict are sect to NaN.