我需要用XlsxWriter在Excel中编写多个矩阵。
但是我想提前指定矩阵的位置
这是我的密码

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的单元格的位置?

最佳答案

若要在工作表中移动数据帧的输出,请在调用startrow时使用命名参数startcolto_excel()在下面的示例中,输出与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()

关于python - Python使用XlsxWriter将多个矩阵写入excel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34417106/

10-11 02:48
查看更多