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 a value in a column.

In [3]:
df['A'] = df['A'].replace(1, 100)

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

Replace multiple values in a column.

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

Replace in a specific column with regex.

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

Replace a value in a column with a function value.

In [8]:
nums = {'0': 'zero', '1': 'one',
        '2': 'two',  '3': 'three',
        '4': 'four', '5': 'five'}

def repl(m):
    return nums[m.group()]

# regex only works for string types
df['B'] = df['B'].astype('string')

df['B'] = df['B'].str.replace(r"^([0-9])$", repl, regex=True)
df
Out[8]:
A B C
0 0 zero a
1 0 one b
2 1 two c
3 1 three d
4 2 four e
5 2 five f