不能在数据框中删除我的 Excel 表格的索引列

2024-09-28 21:07:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个excel文件:

Sentence
12 rue magnol à montpellier
5 avenue de la chantroune 38190 villard bonnot

这个代码是:

import pandas as pd

excel = pd.read_excel(open('Data.xlsx','rb'), sheetname='Data', index=False)
print(excel)

第一行成为列名,所以一切都很好,但当我打印时,excel文件中索引的列似乎进入了我的数据框,我就是无法驾驭它:

                                              Sentence  \
0                          12 rue magnol à montpellier   
1       5 avenue de la chantroune 38190 villard bonnot

你知道吗


Tags: 文件代码datadeexcelsentencelapd
1条回答
网友
1楼 · 发布于 2024-09-28 21:07:09

没有索引就不能有数据帧

但是,excel.values将提供没有索引的原始数组

例如,当写回csv时,可以将index=False,这样就不会将索引写回文件

相关问题 更多 >