简体   繁体   English

如何从 Python 中的 Azure 存储资源管理器中读取文件作为函数?

[英]How to read files from Azure storage explorer in Python as a function?

I want to convert the following code as a function so that it can replicated to read multiple files:我想将以下代码转换为函数,以便它可以复制以读取多个文件:

data = container.download_blob(data)
try:
    print ("Reading the Grower data from blob")
    df  =  pd.read_csv(BytesIO(data.readall()))
    print ("Data read successfully")    
except Exception as e:
    print ("Data load failed due to :" + str(e))

I created the following function:我创建了以下函数:

def download_func(filename,dataframe):
    filename = container.download_blob(filename)
    try:
        print ("Reading the Data from blob")
        dataframe  =  pd.read_csv(BytesIO(filename.readall()))
        print (str(filename)+" data read successfully")    
    except Exception as e:
        print (str(filename)+" data load failed due to :" + str(e))
download_func(data,df)

but there is a name error coming for df但是 df 出现名称错误

How can I proceed from here?我该如何从这里开始? Would be grateful for any help!将不胜感激任何帮助!

from azure.storage.blob import BlockBlobService

block_blob_service = BlockBlobService(account_name='myaccount', account_key='mykey')

block_blob_service.get_blob_to_path('mycontainer', 'myblockblob', 'out-sunset.png')
  • for more information you can go through the SDK documentation有关更多信息,您可以查看 SDK文档

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

相关问题 使用 python azure 函数从 azure blob 存储读取文件 - Read files from azure blob storage using python azure functions 我们如何使用 python 从存储容器 azure 读取文件 - How can we read files from storage container azure using python 如何从 Azure Functions 中的存储容器读取多个文件 - How to read multiple files from a storage container in Azure Functions 如何使用 Python delta-rs 从 Azure Blob 存储中读取数据 - How to read from Azure Blob Storage with Python delta-rs Python:如何从 azure blob 存储中读取一个 doc 文件? - Python: how to read a doc file from azure blob storage? 是否可以从 Azure Blob Storage 容器中读取所有文件,并在使用 Python 读取后删除文件? - Is it possible to read in all the files from an Azure Blob Storage container, and deleting the files after reading with Python? 从 python 中的 azure blob 存储读取文件 - read file from azure blob storage in python python从azure存储帐户中读取 - python read from azure storage account 如何使用 PowerShell 或 python 脚本读取然后编辑或附加存储在 Azure Blob 存储中的 Excel 文件(列和行) - How to read then edit or append an Excel Files (columns and rows ) stored in Azure Blob Storage using PowerShell or python script 如何使用 Python 从 azure blob 读取 docx 文件 - How to read docx files from azure blob using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM