df
df['A'] = df['A'].replace(1, 100)
df
df['A'] = df['A'].replace([0,2], 999)
df
df['A'] = df['A'].astype('str') # regex only works for string types.
df.replace({'A': r'^(1)$'}, {'A': r'\1_new'}, regex=True)
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