【问题标题】:Pandas uses first column as index [closed]Pandas 使用第一列作为索引 [关闭]
【发布时间】:2022-07-12 01:00:34
【问题描述】:

我试图读取我的 CSV 文件,但列与行不匹配,我不知道为什么。 pandas 不是在左边添加了自己的索引还是为什么要使用这个名字?

Picture of my code

Picture of my CSV file

【问题讨论】:

  • 什么不匹配?

标签: python pandas csv


【解决方案1】:

尝试重置索引并重命名列名

df.reset_index(inplace=True)
df.rename(columns={'index':'name'})

【讨论】:

    猜你喜欢
    • 2019-05-27
    • 2019-01-01
    • 2017-10-23
    • 2019-10-29
    • 2022-11-26
    • 2014-09-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    相关资源
    最近更新 更多