有什么好黄页网站,中山网站建设文化平台,泰州企业网站建设公司,物流门户网站开发 报价参考了这篇文章的方法 pandas to_excel:写入数据#xff0c;在同一个sheet中追加数据#xff0c;写入到多个sheet里#xff0c;基本逻辑是#xff1a; 通过数据框获取到该Excel表的行数 df_rows#xff0c;然后将需要存储的数据#xff0c;限制开始写入的行数#xff0c…参考了这篇文章的方法 pandas to_excel:写入数据在同一个sheet中追加数据写入到多个sheet里基本逻辑是 通过数据框获取到该Excel表的行数 df_rows然后将需要存储的数据限制开始写入的行数即startrowdf_rows1 原表中第一个空行然后写入到同一个sheet中。这个方法不会覆盖原来的数据实现在同一个sheet中追加数据。 以及这两个帖子Export dataframe to xlsx - Error “zipfile.BadZipFile: File is not a zip file”
BUG: ExcelWriter.book - attribute not accessible for setting #48780
代码
with pd.ExcelWriter(path, engineopenpyxl, modea,if_sheet_existsoverlay) as writer:df1 pd.DataFrame(pd.read_excel(path, sheet_namesheet1)) df_rows df1.shape[0] #获取原数据的行数#将数据df写入excel中的sheet1表,从第一个空行开始写df.to_excel(writer, sheet_namesheet1,startrowdf_rows1, indexFalse, headerFalse)几个重点
ExcelWriter的mode{‘w’, ‘a’}设为a Append 模式ExcelWriter的if_sheet_exists{‘error’, ‘new’, ‘replace’, ‘overlay’}设定为overlay模式覆盖 将内容写入现有sheet无需先删除但可能会覆盖现有内容。为了避免覆盖现有内容要告诉to_excel方法从新的一行开始写也就是说把to_excel的参数startrow设为“原行数1”