Search code examples
pythonpandasdataframexlwings

How to skip default index (series column on the left) when writing data from dataframe in pandas into Excel through xlwings?


  item  sales
0   A    100
1   B    200
2   C    300
3   D    230
4   E    470
5   F    168

I have a dataset like above in pandas dataframe, and I wrote those data into an Excel file using xlwings, but I don't want to the series index column on the left (0,1,2,3,4...). How do I only import the table without a number index column?


Solution

  • Well, you didn't share your code.

    I used this:

    data = [['A',100],['B',200],['C',300],['D',230],['E',470],['F',168]]
    
    df = pd.DataFrame(data,columns=['item','sales'])
    
    wb = xw.Book()  
    wb = xw.Book(r'C:\Users\XXXXXXX\Documents\xport.xlsx') 
    sht1 = wb.sheets['Hoja1']
    sht1.range('A1').options(pd.DataFrame, index=False).value = df
    
    

    If I open the excel I find this:

    enter image description here