pythonpandasdataframexlwings

Exporting dataframe with xlwings without having a index column


I have following code:

import xlwings as xw

wb = xw.Book('Test.xlsx')
sht1 = wb.sheets['Testsheet']
sht1.range('A8').value = df1

I have want to export my df1 but without column1 (index column). how do i do this?

Right now it looks like this:

Column1 A B C

What I want is this:

A B C

Solution

  • You can set this via options:

    import xlwings as xw
    import pandas as pd
    
    wb = xw.Book('Test.xlsx')
    sht1 = wb.sheets['Testsheet']
    sht1.range('A8').options(pd.DataFrame, index=False).value = df1
    

    See the docs: http://docs.xlwings.org/en/stable/converters.html#pandas-dataframe-converter