我想将 pandas 数据框的索引值转换为小写。请用这个来测试:
import pandas as pd
df = pd.DataFrame([1, 2, 3], columns = ['c'], index = ['A','B','C'])
最佳答案
In [115]:
df.index = df.index.str.lower()
df
Out[115]:
c
a 1
b 2
c 3
编辑
对于 0.16.1
之前的版本(感谢@Joris 指出),您可以调用 map
并传递 str.lower
功能:
In [117]:
df.index = df.index.map(str.lower)
df
Out[117]:
c
a 1
b 2
c 3
关于python - pandas 将索引值转换为小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30576323/