Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming an index in a Pandas Series? [duplicate]

Tags:

python

pandas

I'm trying to rename the index of a series libor I have from DATE to Date:

libor.rename(index={"DATE": "Date"})

The result is unforunately the same as it went in though:

            VALUE
DATE    
1986-01-02  8.12500
1986-01-03  8.12500
1986-01-06  8.18750

I was hoping that 'DATE' would become 'Date'. I'm trying to multiply it with a Dataframe with a 'Date' index, on a column-by-column basis.

How can I rename the index?

like image 547
cjm2671 Avatar asked Jan 07 '23 02:01

cjm2671


2 Answers

Just change the name property of the index.

libor.index.name = 'Date'
like image 196
Alexander Avatar answered Jan 08 '23 16:01

Alexander


you can use rename_axis() for that:

Example:

In [310]: s
Out[310]:
Index
0    1
1    2
2    3
dtype: int64

In [312]: s = s.rename_axis('idx')

In [313]: s
Out[313]:
idx
0    1
1    2
2    3
dtype: int64
like image 41
MaxU - stop WAR against UA Avatar answered Jan 08 '23 14:01

MaxU - stop WAR against UA