Python使用XlsxWriter将多个matrix写入excel
我需要使用XlsxWriter在Excel中编写多个matrix。
但是我想提前指定matrix的位置
这是我的代码
writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter') CC1 = Get_Data(test1) ## get the corresponding matrix df = DataFrame(CC) ## put into a dataframe format df.to_excel(writer, sheet_name="sheet1") ## write into excel CC2 = Get_Data(test2) ## get the corresponding matrix df = DataFrame(CC2) ## put into a dataframe format df.to_excel(writer, sheet_name="sheet1") ## write into excel writer.save()
我怎样才能指定单元格的位置,我可以插入相应的daraframe?
要移动工作表中DataFrame的输出, startcol
在调用to_excel()
使用命名参数startrow
和startcol
。 在下面的例子中,输出放在E3的左上方单元格中。
import numpy as np import pandas as pd from xlsxwriter.utility import xl_range writer = pd.ExcelWriter('test.xlsx', engine='xlsxwriter') workbook = writer.book df = pd.DataFrame(data=np.random.rand(255)) df.to_excel( writer, 'TEST', startcol=4, startrow=2 ) writer.close()