I was seeking a pandas solution to the following problem
Dataframe
col1,col2
1,a
2,a
3,a
4,a
Desired output: Replace every instance of a in col2 with a different value
col1,col2
1,cat
2,elephant
3,monkey
4,tiger
I've tried the replace() function, but that replace all occurrences of a
df = df['col2'].replace('a','cat')
But doing this results in
col1,col2
1,cat
2,cat
3,cat
4,cat