Azure函数-Excel的Pandas数据框为空



根据上一个堆栈溢出问题Azure Function-Pandas Dataframe到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"
}

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

最新更新