1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > python pandas向已有excel添加新表sheet/添加数据

python pandas向已有excel添加新表sheet/添加数据

时间:2023-06-06 23:20:38

相关推荐

python pandas向已有excel添加新表sheet/添加数据

python pandas向已有excel添加新表sheet/添加数据

python pandas向已有excel添加新表sheet/添加行数据

import pandas as pdfrom openpyxl import load_workbookwriter = pd.ExcelWriter(excel_name,engine='openpyxl')# pylint: disable=abstract-class-instantiatedone_img_info = ['file', 1]one_img_info = pd.DataFrame(one_img_info)# 创建新excelif not os.path.exists(excel_name):one_img_info.to_excel(writer, sheet_name=dir_i, index = False)else:# 1.向已有excel创建新sheetbook = load_workbook(excel_name)writer.book = bookone_img_info.to_excel(writer, sheet_name=dir_i, index = False)# 2.向已有excel添加新行(注释上面三行)# df= pd.DataFrame(pd.read_excel(excel_name,sheet_name=dir_i), index=None) # out_df = pd.concat([df,one_img_info],axis=0)# out_df.to_excel(writer, sheet_name=dir_i, index = False)writer.save()writer.close()

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。