【问题标题】:Saving a file into Azure Blob storage将文件保存到 Azure Blob 存储
【发布时间】:2020-08-25 07:24:53
【问题描述】:

我在 Azure 机器学习平台/云上运行 Python 代码,但我不知道如何将生成的数据帧保存到 Azure Blob 存储中的 csv 文件中。谁能告诉我该怎么做或指出我可以在哪里阅读更多相关信息?

【问题讨论】:

    标签: python azure save azure-blob-storage blobstorage


    【解决方案1】:

    您可以尝试使用以下 python 代码将文件上传到 Azure 博客吗:

    global service_client
    
    service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format("https", 'Storage_account_name'), credential='Storage_Account_Key')
    
    #upload file to ADLS Gen 2
    file_system_client = service_client.get_file_system_client(file_system="your_container_name")
    
    directory_client = file_system_client.get_directory_client("my-directory")
    
    file_client = directory_client.create_file("uploaded-file.txt")
    local_file = open("C:\\Users\\xxxxxxx\\Desktop\\testFile.txt", 'r')
    
    file_contents = local_file.read()
    
    file_client.append_data(data=file_contents, offset=0, length=len(file_contents))
    
    file_client.flush_data(len(file_contents))
    

    有关完整代码的更多详细信息,请访问this link

    【讨论】:

      猜你喜欢
      • 2021-09-20
      • 1970-01-01
      • 2021-03-19
      • 1970-01-01
      • 2020-02-11
      • 1970-01-01
      • 2017-08-18
      • 2021-12-08
      • 2013-02-06
      相关资源
      最近更新 更多