简体   繁体   English

如何从 Azure function 在 Z23EEEB4347BDD26BDDFC6B75

[英]How to read xlsx blob into pandas from Azure function in python

I am reading in.xslx data from a blob in an azure function.我正在从 azure function 中的 blob 中读取 in.xslx 数据。 My code looks something like this:我的代码看起来像这样:

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'))
   

The issue is when I try to decode the files, I get the following error:问题是当我尝试解码文件时,出现以下错误:

ValueError: Protocol not known: PK...

And a lot of strange characters after the "...".而且“……”后面还有很多奇怪的字符。 Any thoughts on how to properly read in these files?关于如何正确读取这些文件的任何想法?

Please refer to my code, it seems that you don't need to add decode('ISO-8859-1') :请参考我的代码,好像不需要加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}")

Note: Your function.json should look like this.注意:您的function.json应如下所示。 Otherwise, an error will occur.否则会出现错误。

{
      "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"
    }

The difference between this and your function.json is that you are missing a dataType attribute.这与您的function.json之间的区别在于您缺少dataType属性。

在此处输入图像描述

My test result is like this, there are seems to be no problems.我的测试结果是这样的,似乎没有问题。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AZURE Function 从 AZURE BLOB 读取 XLSX - AZURE Function read XLSX from AZURE BLOB 如何在不创建临时文件的情况下使用 Pandas 从 Azure Blob 读取 .xlsx 格式文件 - How to read .xlsx format file from Azure Blob using pandas without creating temporary file 如何从Azure Function Python动态读取blob文件 - How to dynamically read blob file from Azure Function Python 使用 Python 从 Azure Blob 下载 XLSX 文件 - Download XLSX File from Azure Blob in Python 从 azure blob 存储读取 xlsx 到 pandas dataframe 而不创建临时文件 - Read xlsx from azure blob storage to pandas dataframe without creating temporary file 如何使用 python 和 pandas read_fwf ZC1C42542074E68384F5D1 处理位于 Azure blob 存储中的文件 - How to process a file located in Azure blob Storage using python with pandas read_fwf function 如何在 python 中使用 Azure 函数读取 Azure blob 文件? - how to read the Azure blob file with Azure function in python? 如何从 Azure blob 存储中将镶木地板文件读入 pandas - How to read parquet file into pandas from Azure blob store 如何从 Azure Python function blob 输入绑定中读取镶木地板文件? - How to read parquet file from Azure Python function blob input binding? 如何使用 Python 从 Azure Blob 容器读取文件 - How to read a file from Azure Blob Container using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM