写数据框以优于标题

我想在Excel中打印一个数据框。 我正在使用ExcelWriter,如下所示:

writer = pd.ExcelWriter('test.xlsx') df = DataFrame(C,ind) # C is the matrix and ind is the list of corresponding indices df.to_excel(writer, startcol = 0, startrow = 5) writer.save() 

这产生了我所需要的,除此之外,我想添加一个标题与一些文本(解释)的表顶部的数据( startcol=0startrow=0 )。

如何使用ExcelWriter添加string标题?

你应该可以使用write_string方法在单元格中写入文本,并将一些对XlsxWriter的引用添加到代码中:

 writer = pd.ExcelWriter('test.xlsx') df = DataFrame(C,ind) # C is the matrix and ind is the list of corresponding indices df.to_excel(writer, startcol = 0, startrow = 5) worksheet = writer.sheets['Sheet1'] worksheet.write_string(0, 0, 'Your text here') writer.save() 

这将做的伎俩:

 In[16]: sheet = writer.sheets['Sheet1'] #change this to your own In[17]: sheet.write(0,0,"My documentation text") In[18]: writer.save()