concept rename in category pandas

appears as: rename
Pandas in Action

This is an excerpt from Manning's book Pandas in Action.

The rename method is an alternate option. We can pass its columns parameter a dictionary with keys representing the existing column names and values representing their new names.

In  [91] nba.rename(columns = { "Date of Birth": "Birthday" })
 
Out [91]
 
                               Team Position   Birthday       Pay
Name_____________________________________________________________                                                            
Shake Milton     Philadelphia 76ers       SG 1996-09-26   1445697
Christian Wood      Detroit Pistons       PF 1995-09-27   1645357
PJ Washington     Charlotte Hornets       PF 1998-08-23   3831840
Derrick Rose        Detroit Pistons       PG 1988-10-04   7317074
Marial Shayok    Philadelphia 76ers        G 1995-07-26     79568
            …               …              …          …         …
Austin Rivers       Houston Rockets       PG 1992-08-01   2174310
Harry Giles        Sacramento Kings       PF 1998-04-22   2578800
Robin Lopez         Milwaukee Bucks        C 1988-04-01   4767000
Collin Sexton   Cleveland Cavaliers       PG 1999-01-04   4764960
Ricky Rubio            Phoenix Suns       PG 1990-10-21  16200000
 
As always, use the inplace parameter to make the operation permanent.
 
In  [92] nba.rename(
           columns = { "Date of Birth": "Birthday" },
           inplace = True
         )

The rename method can rename an index label. The example below swaps "Giannis Antetokounmpo" with his popular nickname "Greek Freak".