当前位置: 动力学知识库 > 问答 > 编程问答 >

python - pandas convert index values to lowercase

问题描述:

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'])

网友答案:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: