删除pandas标签

我想通过python插入一些excel文件列中的数据。 我正在使用pandas在现有的Excel文件中插入和写入数据。

41 5 5 40 96 5 25 5 3 12 6 29 

但它扰乱了整个结构并删除了一些数据。

 41 0 5 5 0 10 96 5 1 20 5 3 2 30 6 29 3 20 4 15 5 30 6 45 

我只想插入我的数据没有antdatalabels。 这是我的代码:

 import pandas as pd import win32com.client xlApp = win32com.client.Dispatch("Excel.Application") wkbk = xlApp.Workbooks.Open("D:\PycharmProjects\\untitled1\\arrays.xlsx") wksht = wkbk.ActiveSheet; wksht.Columns(2).EntireColumn.Insert() xlApp.DisplayAlerts = False xlApp.ActiveWorkbook.Save() xlApp.Quit() from openpyxl import load_workbook book = load_workbook('arrays.xlsx') writer = pd.ExcelWriter('arrays.xlsx', engine='openpyxl') writer.book = book writer.sheets = dict((ws.title, ws) for ws in book.worksheets) data = [10, 20, 30, 20, 15, 30, 45] df = pd.DataFrame(data) df.to_excel(writer, sheet_name='Sheet1') writer.save() 

从你的例子看来,你写出你的数据框标签和列标题。 您可以使用to_excel方法中的index=False header=False选项来禁止这些选项:

 df.to_excel(index=False, header=False)