从熊猫导出到没有行名(索引)的_excel?

我想把熊猫的数据框打印到 Excel 里。这里我使用的是 to _ excel ()函数。但是,我发现 Excel 中的第一列是“ index”,

0   6/6/2021 0:00   8/6/2021 0:00
1   4/10/2024 0:00  6/10/2024 0:00
2   4/14/2024 0:00  6/14/2024 0:00

有办法除掉第一纵队吗?

208492 次浏览

You need to set index=False in to_excel in order for it to not write the index column out, this semantic is followed in other Pandas IO tools, see http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_excel.html and http://pandas.pydata.org/pandas-docs/stable/io.html

Example: index = False

import pandas as pd


writer = pd.ExcelWriter("dataframe.xlsx", engine='xlsxwriter')
dataframe.to_excel(writer,sheet_name = dataframe, index=False)
writer.save()

I did that and got the error message:

TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed.

The code is as follows where 'test' is a dataframe with no column names

test = pd.DataFrame(biglist)
writer = pd.ExcelWriter("test.xlsx", engine='xlsxwriter')
test.to_excel(writer,sheet_name=test, index=False)
writer.save()