How to I stop Pandas to_excel() function creating an extra column with the indexes in? If I run the following:
import pandas as pd
df = pd.read_excel('in.xlsx')
#do some stuff to the dataframe
writer = pd.ExcelWriter('out.xlsx')
df.to_excel(writer)
writer.save()
.. the newly created file (out.xlsx
) has an additional column which I don't want. I just want the columns identified in df.columns
outputting without the additional indexes column.
This is a small step in a larger process so i can't just manually delete the column. Also, i don't want to use any other Excel writing packages such as XlsxWriter
Many thanks!
You need to set index
property to false
, like this:
df.to_excel(writer, index=False)
As decribed in pandas documentation: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_excel.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With