Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas convert index values to lowercase

Tags:

python

pandas

I want to convert index values of a pandas dataframe to lowercase. Please use this to test:

import pandas as pd
df = pd.DataFrame([1, 2, 3], columns = ['c'], index = ['A','B','C'])
like image 746
grokkaine Avatar asked Jun 01 '15 14:06

grokkaine


People also ask

How do I change to lower case in Pandas?

lower() . Converts all characters to lowercase.

How do you make all values in a column lowercase?

Select the column you need to make the values capital or lowercase, and then click Kutools > Text > Change Case.

How do you lowercase a string in a column in Python?

str. lower() and df["x"] = df["x"]. str. lower() .


1 Answers

You can use the vectorised str method lower:

In [115]:
df.index = df.index.str.lower()
df

Out[115]:
   c
a  1
b  2
c  3

EDIT

For versions older than 0.16.1 (thanks to @Joris for pointing that out) you can call map and pass the str.lower function:

In [117]:
df.index = df.index.map(str.lower)
df

Out[117]:
   c
a  1
b  2
c  3
like image 188
EdChum Avatar answered Oct 14 '22 08:10

EdChum