如何在 AWS Glue 中编译多个 Excel 文件并将其保存在一个 Excel 文件中
我能够生成多个 Excel 文件并在本地计算机上使用 pandas.ExcelWriter 对其进行编译,但如何使用 AWS Glue 获得相同的结果?
def backup_report(filename):
with pd.ExcelWriter(local_excel_file_path + '/{0}.xlsx'.format(filename), engine='xlsxwriter') as writer:
# ------- insert metrics that x need calculation -------
op_AdReq_fnl.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=2, header=True)
op_dirt_imps.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=8, header=False)
op_prog_imps.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=12, header=False)
op_hse_imps.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=16, header=False)
op_FillRt_fnl.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=29, header=False)
op_dirt_rvn.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=57, header=False)
op_prog_rvn.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=61, header=False)
workbook = writer.book
worksheet = writer.sheets['weekly']
# ------- report date -------
update_dt = date.today().strftime("%d %b %Y")
worksheet.write(0,0,'Last Update: '+ update_dt)
report_dt = start_dt + " - " + end_dt
worksheet.write(0, 1, '('+ report_dt + ')')
# ------- write index names -------
metric_format = workbook.add_format({'bold': False, 'font_color': 'black', 'align': 'left', 'valign': 'vcenter'})
metric_format.set_border()
metric_format2 = workbook.add_format({'bold': True, 'font_color': 'black', 'align': 'left', 'valign': 'vcenter'})
metric_format2.set_border()
metric_format2.set_bg_color('silver')
fmt_number = workbook.add_format({'num_format': '#,,##0'})
fmt_percent = workbook.add_format({'num_format': '0%'})
writer.save()
writer.close()
I able to generate several Excel files and compile it using pandas.ExcelWriter on my local machine but how do I achieve the same result using AWS Glue?
def backup_report(filename):
with pd.ExcelWriter(local_excel_file_path + '/{0}.xlsx'.format(filename), engine='xlsxwriter') as writer:
# ------- insert metrics that x need calculation -------
op_AdReq_fnl.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=2, header=True)
op_dirt_imps.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=8, header=False)
op_prog_imps.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=12, header=False)
op_hse_imps.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=16, header=False)
op_FillRt_fnl.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=29, header=False)
op_dirt_rvn.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=57, header=False)
op_prog_rvn.to_excel(writer, sheet_name='weekly', index=True, startcol=0, startrow=61, header=False)
workbook = writer.book
worksheet = writer.sheets['weekly']
# ------- report date -------
update_dt = date.today().strftime("%d %b %Y")
worksheet.write(0,0,'Last Update: '+ update_dt)
report_dt = start_dt + " - " + end_dt
worksheet.write(0, 1, '('+ report_dt + ')')
# ------- write index names -------
metric_format = workbook.add_format({'bold': False, 'font_color': 'black', 'align': 'left', 'valign': 'vcenter'})
metric_format.set_border()
metric_format2 = workbook.add_format({'bold': True, 'font_color': 'black', 'align': 'left', 'valign': 'vcenter'})
metric_format2.set_border()
metric_format2.set_bg_color('silver')
fmt_number = workbook.add_format({'num_format': '#,,##0'})
fmt_percent = workbook.add_format({'num_format': '0%'})
writer.save()
writer.close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 AWS Glue 中成功使用了
pd.Excelwriter
。I successfully use the
pd.Excelwriter
in AWS Glue.