change header name in pandas code example

Example 1: renaming headers pandasd

df = df.rename(columns={"old_col1": "new_col1", "old_col2": "new_col2"})

Example 2: rename column pandas

>>> df.rename(index={0: "x", 1: "y", 2: "z"})
   A  B
x  1  4
y  2  5
z  3  6

Example 3: how to change a header in pandas

# Can just use df.columns to rename

>>> df = pd.DataFrame({'$a':[1,2], '$b': [10,20]})
>>> df.columns = ['a', 'b']
>>> df
   a   b
0  1  10
1  2  20

Example 4: rename column pandas

>>> df.index
RangeIndex(start=0, stop=3, step=1)
>>> df.rename(index=str).index
Index(['0', '1', '2'], dtype='object')