You could use DataFrame.replace
with regex
parameter set to True and pass the mapping dictionary.
df.replace(dictionary, regex=True)
# col2
# 0 5
# 1 abc
# 2 8
This usage of df.replace
is less known. You can read more about it here.
CLICK HERE to find out more related problems solutions.