xxxxxxxxxx
df['column name'] = df['column name'].replace(['1st old value','2nd old value', ],['1st new value','2nd new value', ])
xxxxxxxxxx
In [11]: df['n'].replace({'a': 'x', 'b': 'y', 'c': 'w', 'd': 'z'})
Out[11]:
0 z
1 x
2 y
3 w
4 w
5 x
6 z
7 y
Name: n, dtype: object
In [12]: df['n'] = df['n'].replace({'a': 'x', 'b': 'y', 'c': 'w', 'd': 'z'})
xxxxxxxxxx
import pandas as pd
d1 = {'Name': ['Pankaj', 'Lisa', 'David'], 'ID': [1, 2, 3], 'Role': ['CEO', 'Editor', 'Author']}
df = pd.DataFrame(d1)
print('Source DataFrame:\n', df)
df.rename(index={0: '#0', 1: '#1', 2: '#2'}, columns={'Name': 'EmpName', 'ID': 'EmpID', 'Role': 'EmpRole'}, inplace=True)
print('Source DataFrame:\n', df)