Remove default formatting in header when converting pandas DataFrame to excel sheet
Based largely on an example provided in the Xlsxwriter Docs (link here), the fully reproducible example below removes the default pandas header format in pandas 0.24.2. Of note is that in df.to_excel()
, I'm changing the header
and startrow
parameters.
import xlsxwriter
import pandas as pd
import numpy as np
# Creating a dataframe
df = pd.DataFrame(np.random.randn(100, 3), columns=list('ABC'))
column_list = df.columns
# Create a Pandas Excel writer using XlsxWriter engine.
writer = pd.ExcelWriter("test.xlsx", engine='xlsxwriter')
df.to_excel(writer, sheet_name='Sheet1', startrow=1, header=False, index=False)
# Get workbook and worksheet objects
workbook = writer.book
worksheet = writer.sheets['Sheet1']
for idx, val in enumerate(column_list):
worksheet.write(0, idx, val)
writer.save()
print(pd.__version__)
Expected Output:
0.24.2