In [2]:
df
Out[2]:
A B C
0 0 0 a
1 0 1 b
2 1 2 c
3 1 3 d
4 2 4 e
5 2 5 f

Replace values in specific columns.

In [3]:
df.replace({"A":1,"B":2}, 999)
Out[3]:
A B C
0 0 0 a
1 0 1 b
2 999 999 c
3 999 3 d
4 2 4 e
5 2 5 f

Replace multiple values in specific columns.

In [4]:
df.replace({"A":[1,2],"B":[2,3]}, 999)
Out[4]:
A B C
0 0 0 a
1 0 1 b
2 999 999 c
3 999 999 d
4 999 4 e
5 999 5 f

Replace values in specific columns with regex.

In [5]:
df.replace({'A': r'^(1)$', 'B': r'^(2)$'}, r'\1_new', regex=True)
Out[5]:
A B C
0 0 0 a
1 0 1 b
2 1 2 c
3 1 3 d
4 2 4 e
5 2 5 f