Export from pandas to_excel without row names (index)?

PandasPython 2.7IndexingExport to-Excel

Pandas Problem Overview


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",

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?

Pandas Solutions


Solution 1 - Pandas

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

Solution 2 - Pandas

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() 

Solution 3 - Pandas

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()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlshengView Question on Stackoverflow
Solution 1 - PandasEdChumView Answer on Stackoverflow
Solution 2 - PandasAnurag SinghView Answer on Stackoverflow
Solution 3 - PandasGTaylorView Answer on Stackoverflow