I have the following DF
| a | b | |
|---|---|---|
| Test1 | 2 | 1 |
| Test2 | 3 | 2 |
What I currently do is the following :
DF.reset_index().set_index('b')
which give the following output :
| b | a | index |
|---|---|---|
| 1 | 2 | Test1 |
| 2 | 3 | Test2 |
But what if I don't want the column to be named as "index" ?
For example I wish to have the following output : (Replace "index" by "TestName")
| b | a | TestName |
|---|---|---|
| 1 | 2 | Test1 |
| 2 | 3 | Test2 |
DF.reset_index().set_index('b').rename(columns={'index':'TestName'}). There's alsorename_axisfunction as well.DF.rename(columns={'index':'TestName'}, inplace=True)