如何在 AWS Glue 中编译多个 Excel 文件并将其保存在一个 Excel 文件中

发布于 2025-01-12 20:28:39 字数 1971 浏览 0 评论 0原文

我能够生成多个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事↓在人 2025-01-19 20:28:39

我在 AWS Glue 中成功使用了 pd.Excelwriter

def backup_report(filename):
    with io.BytesIO() as output:
        with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
             .
             .
             .
    writer.save()
    writer.close()

I successfully use the pd.Excelwriter in AWS Glue.

def backup_report(filename):
    with io.BytesIO() as output:
        with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
             .
             .
             .
    writer.save()
    writer.close()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文