您需要
write或
write_string:
text1 = "some text here"text2 = "other text here"df = pd.Dataframe({"a": [1,2,3,4,5], "b": [6,7,8,9,10], "c": [11,12,13,14,15]})writer = pd.ExcelWriter("test.xlsx", engine="xlsxwriter")df.to_excel(writer, startrow=4, startcol=0)worksheet = writer.sheets['Sheet1']worksheet.write(0, 0, text1)worksheet.write(1, 0, text2)#another solution#worksheet.write_string(0, 0, text1)#worksheet.write_string(1, 0, text2)writer.save()
注意:
write和
write_string实际上是
xlsxwriter包函数。要使用它们,必须安装该软件包并
pd.ExcelWriter必须使用
xlsxwriter引擎对其进行初始化(在pandas
1.0.5中,它默认为io.excel。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)