将文件保存到 Azure Blob 存储中

问题描述 投票:0回答:1

我正在Azure Machine Learning platformcloud上运行一段Python代码,我想不通如何将生成的数据帧保存到Azure Blob存储中的csv文件中。谁能告诉我如何做到这一点,或者指出我在哪里可以阅读更多关于它的信息?

python azure save azure-storage-blobs blobstorage
1个回答
0
投票

你可以尝试上传文件到Azure博客使用下面的python代码。

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

更多的细节,以完整的代码,访问 这个环节

© www.soinside.com 2019 - 2024. All rights reserved.