Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export from pandas to_excel without row names (index)?

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?

like image 404
lsheng Avatar asked Feb 28 '14 07:02

lsheng


People also ask

How do I save a pandas DataFrame in Excel without index?

Pandas to_excel() function has number of useful arguments to customize the excel file. For example, we can save the dataframe as excel file without index using “index=False” as additional argument. One of the common uses in excel file is naming the excel sheet.

How do I save a CSV file without indexing?

pandas DataFrame to CSV with no index can be done by using index=False param of to_csv() method. With this, you can specify ignore index while writing/exporting DataFrame to CSV file.

How do you remove an index from a data frame?

The most straightforward way to drop a Pandas dataframe index is to use the Pandas . reset_index() method. By default, the method will only reset the index, forcing values from 0 - len(df)-1 as the index. The method will also simply insert the dataframe index into a column in the dataframe.

How do I remove an index from a DataFrame in Excel?

We can remove the index column in existing dataframe by using reset_index() function. This function will reset the index and assign the index columns start with 0 to n-1.


1 Answers

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

like image 158
EdChum Avatar answered Sep 30 '22 14:09

EdChum