pandas 没有行名(索引)从熊猫导出到_excel?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22089317/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Export from pandas to_excel without row names (index)?
提问by lsheng
I'm trying to print out a dataframe from pandas into Excel. Here I am using to_excel() functions. However, I found that the 1st column in Excel is the "index",
我正在尝试将 Pandas 中的数据框打印到 Excel 中。这里我使用 to_excel() 函数。但是,我发现 Excel 中的第一列是“索引”,
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
Is there any ways to get rid of the first column?
有没有办法摆脱第一列?
回答by EdChum
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.htmland http://pandas.pydata.org/pandas-docs/stable/io.html
您需要设置index=False
into_excel
以便它不会将索引列写出,其他 Pandas IO 工具也遵循此语义,请参阅http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame。 to_excel.html和http://pandas.pydata.org/pandas-docs/stable/io.html
回答by Anurag Singh
Example: index = False
示例:索引 = False
import pandas as pd
writer = pd.ExcelWriter("dataframe.xlsx", engine='xlsxwriter')
dataframe.to_excel(writer,sheet_name = dataframe, index=False)
writer.save()