有没有一种方法可以从Python中的特定单元格开始写入数据帧

时间:2020-10-12 14:47:40

标签: python python-3.x excel dataframe export

我试图将DataFrame写入现有的Excel工作表中,该工作表将使用导入的数据执行一些操作。我试图使用openpyxl库和dataframe_to_rows函数来实现它。

它实际上确实将数据帧写入了良好的工作表中,但没有从单元格的开头写入数据(excels函数要求从特定单元格开始的数据)

这是我的代码:

sheet_name = ['Zones','Bilan','CTA', "Annuel", "Ventilation"] # The names of the differents sheet where i need to import my DataFrames 
vect_Data =  [Data1,Data2,Data3, sortie_annuel, Ventil_data] # The DataFrames i need to import in the sheets

wb = op.load_workbook(filename = nom_excel) # I imported openpyxl as op 
for i in range(len(sheet_name)):
    ws = wb[sheet_name[i]]
    for cells in ws :
        for cell in cells : 
            cell.value = None
    for r in dataframe_to_rows(vect_Data[i] , index=False , header=True): 
        ws.append(r)
        
wb.save(filename = nom_excel)

是否有一种方法可以强制dataframe_to_rows函数从特定的单元格开始?

谢谢您的回答。

0 个答案:

没有答案