python - 在 Pandas 中重命名系列

标签 python pandas

我正在处理系列,我想知道在写入文件时如何重命名系列。例如,我的输出 csv 包含以下内容:

Gene_Name,0
A2ML1,15
AAK1,8

我希望它是以下内容:

Gene_Name,Count
A2ML1,15
AAK1,8

注意:我不希望我的 header 是“Gene_Name,0”,而是“Gene_Name,Count”。我怎样才能做到这一点?

最佳答案

要使“Count”成为您系列的名称,只需使用 your_series.name = "Count" 进行设置,然后像这样调用 to_csv:your_series.to_csv("c:\\output.csv", header=True, index_label="Gene_Name").

关于python - 在 Pandas 中重命名系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16350864/

相关文章:

Python 字典 : "in" vs "get"

python - 如何替换数据框中的索引

Python读取LTspice图导出

python - Numpy python 数组切片

python - 当我尝试使用 subprocess.call 时,导致 "AttributeError: ' tuple' object has no attribute 'rfind' 的原因是什么

python - 如何阻止 Odoo 多次调用函数?

python - 摆脱 Pandas 中的分层索引

python - Pandas:SettingWithCopyWarning 触发位置

python pandas dataframe head() 什么都不显示

python - 运行 Adam 优化器