python - pandas 将索引值转换为小写

标签 python pandas

我想将 pandas 数据框的索引值转换为小写。请用这个来测试:

import pandas as pd
df = pd.DataFrame([1, 2, 3], columns = ['c'], index = ['A','B','C'])

最佳答案

您可以使用向量化的 str方法 lower :

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/

相关文章:

python - 类型错误 : descriptor 'strftime' for 'datetime.date' objects doesn't apply to a 'NoneType' object

javascript - 可以使用 scrapy 从使用 AJAX 的网站中抓取动态内容吗?

python - 从 Python 中的规则间隔列表中提取整数项

python - Pandas 用三点和 seaborn 散点图颜色

python Pandas : select column with the number of unique values greater than 10

python - ** 之后的 MetaSerialisable 对象参数必须是映射,而不是 unicode

python - 在 python 中向绘制线(不是轴)添加刻度线?

python - DataFrame 子集的 Pandas 平均时间戳

pandas - 根据索引条件过滤 df

python - Pandas:根据开始和结束日期范围逐月求和