PythonBestie007
PythonBestie007

Reputation: 39

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

Upvotes: 1

Views: 5607

Answers (3)

dwd123
dwd123

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

Felix Zumstein
Felix Zumstein

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

Chan
Chan

Reputation: 1

You may select specified column like this:

df1 = df1.reset_index()
df2 = df1[['A', 'B', 'C']]

Upvotes: 0

Related Questions