I have the following data frame.
col1 col2 col3
1 1 1
2 2 2
3 1 2
3 3 3
I want to replace numerical values based on the following mappings
col1: {1: dog, 2: cat, 3: bird}
col2: {1: yellow, 2: orange, 3: red}
col3: {1: dave, 2: pete, 3: tom}
How can I do this in Python through method chaining?
Expected Output:
col1 col2 col3
dog yellow dave
cat orange pete
bird yellow pete
bird red tom
I know that there is a replace function but it works like the following:
df[col1].replace('old_val', 'new_val')
I want to do something like this (similar to the assign method where I can just keep adding new columns in the method):
#pseudocode
df.replace(col1 = mapping1, col2 = mapping2, col3 = mapping3)
How can I do this in pandas?