Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas rename index values

Tags:

python

pandas

I have the following dataframe in pandas (python):

      B.  X.  Y.  
A
alpha 3. 5.  5
beta  9. 9.  11

I want to change 'alpha' for another name, like 'mu'. What should I do?

like image 254
nunodsousa Avatar asked Nov 29 '16 00:11

nunodsousa


People also ask

How do you rename a series index in Python?

rename() function is used to alter Series index labels or name for the given Series object. inplace : Whether to return a new Series. If True then value of copy is ignored. level : In case of a MultiIndex, only rename labels in the specified level.


1 Answers

Use rename with parameter index
pass a dictionary to the index parameter

df.rename(index={'alpha': 'mu'})

enter image description here

like image 191
piRSquared Avatar answered Oct 11 '22 13:10

piRSquared