i have a dataframe:
A B C
1 1 1
2 2 2
3 3 3
Now i want to replace 1 with 3, 2 with 7 ,and 3 with 10.
I write the code:
df['A'].replace(3, 10, inplace = True)
df['A'].replace(1, 3, inplace = True)
df['A'].replace(2, 7, inplace = True)
Works fine for me. I do have to replace 3 with 10 first , because if we change the 1 with 3 first, then the transformed 3 will again changed and finally replaced with 10.
Though i have to replace the same formattion for several columns, how come i use function?
I tried to write one but i failed, any guidance?