【问题标题】:Azure Function - Pandas Dataframe to Excel is EmptyAzure 函数 - 到 Excel 的 Pandas 数据框为空
【发布时间】:2020-11-17 02:50:42
【问题描述】:

遵循上一个堆栈溢出问题Azure Function - Pandas Dataframe to Excel 的答案后,我已经能够将 xlsx 文件存储在存储 blob 中,但该文件为空。我在本地使用 Azurite 进行调试,所以我可以看到数据框不为空,outputblob 对象也不为空,但存储容器中生成的 .xlsx 文件是 0 字节文件。

这是我正在运行的相关“写入 blob”代码。

# Write data to storage blob
        df = pd.DataFrame(all_data, columns=COLUMN_NAMES)
        if not df.empty:
            xlb = io.BytesIO()
            writer = pd.ExcelWriter(xlb, engine= 'xlsxwriter') # pylint: disable=abstract-class-instantiated
            df.to_excel(writer, index=False)
            xlb.seek(0)
            outputblob.set(xlb)
            logging.info(f"Write OK. Number of rows: {df.shape[0]} ")

这里是来自function.json 的绑定部分:

"bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 2 * * * *"
    },
    {
      "type": "blob",
      "direction": "out",
      "name": "outputblob",
      "path": "performance-alerting-data/SignInApp/outputblob.xlsx",
      "connection": "AzureWebJobsStorage"
    }

【问题讨论】:

    标签: python excel pandas azure-functions azure-blob-storage


    【解决方案1】:

    我发现了错误。我忘了在df.to_excel() 之后添加writer.save()。现在工作正常,Excel文件写入存储容器并保存为excel文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 2017-09-06
      • 2022-08-16
      • 1970-01-01
      • 2019-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多