如何通过python ExcelWriter生成excel中的列标题

时间:2017-09-20 12:18:29

标签: pandas pandas.excelwriter

我通过原始查询从django数据库中获取excel数据。生成了Excel,但缺少列标题。 请提出一些方法来获得该标题。

import pandas as pd
from pandas import ExcelWriter
df1 = pd.DataFrame(row1)
try:
    from StringIO import StringIO
except:
    from io import StringIO
import xlwt
wb = Workbook()
writer = ExcelWriter("XYZ.xlsx",options={'remove_timezone': True})
xl_out = StringIO()
writer.path = xl_out
ws1 = wb.add_sheet("abc")
for col_num, value in enumerate(df1.columns.values):
       ws1.write(1,col_num + 1, 'value')
df1.to_excel(writer,"abc", index= True, header=True)
writer.save()

0 个答案:

没有答案