Reputation: 39
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
Upvotes: 1
Views: 5607
Reputation: 41
Felix's answer worked for me with one minor change:
sht1.range('A8').options(index=False).value = df1
(removed pd.DataFrame
from the 'options' argument)
I also noticed you can omit headers by setting headers=False
.
Upvotes: 0
Reputation: 7070
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
Upvotes: 5
Reputation: 1
You may select specified column like this:
df1 = df1.reset_index()
df2 = df1[['A', 'B', 'C']]
Upvotes: 0