gpt4 book ai didi

python - 如何从Python中的Azure函数将xlsx blob读入pandas

转载 作者:行者123 更新时间:2023-12-02 23:16:09 24 4
gpt4 key购买 nike

我正在从 azure 函数中的 blob 读取 .xslx 数据。我的代码看起来像这样:

def main(techdatablob: func.InputStream, crmdatablob: func.InputStream, outputblob: func.Out[func.InputStream]):

# Load in the tech and crm data
crm_data = pd.read_excel(crmdatablob.read().decode('ISO-8859-1'))
tech_data = pd.read_excel(techdatablob.read().decode('ISO-8859-1'))

问题是当我尝试解码文件时,出现以下错误:

ValueError: Protocol not known: PK...

“...”后面还有很多奇怪的字符。关于如何正确读取这些文件有什么想法吗?

最佳答案

请引用我的代码,好像不需要添加decode('ISO-8859-1'):

import logging
import pandas as pd
import azure.functions as func


def main(techdatablob: func.InputStream, crmdatablob: func.InputStream, outputblob: func.Out[func.InputStream]):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {techdatablob.name}\n"
f"Blob Size: {techdatablob.length} bytes")

# Load in the tech and crm data
crm_data = pd.read_excel(crmdatablob.read())
logging.info(f"{crm_data}")
tech_data = pd.read_excel(techdatablob.read())
logging.info(f"{tech_data}")

注意:您的 function.json 应如下所示。否则会出现错误。

{
"name": "techdatablob",
"type": "blobTrigger",
"direction": "in",
"path": "path1/{name}",
"connection": "example"
},
{
"name": "crmdatablob",
"dataType": "binary",
"type": "blob",
"direction": "in",
"path": "path2/data.xlsx",
"connection": "example"
},
{
"name": "outputblob",
"type": "blob",
"direction": "out",
"path": "path3/out.xlsx",
"connection": "example"
}

它与您的 function.json 之间的区别在于您缺少 dataType 属性。

enter image description here

我的测试结果是这样的,好像没有问题。

enter image description here

关于python - 如何从Python中的Azure函数将xlsx blob读入pandas,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66147071/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com