将Python数据帧作为CSV写入Azure Blob
我有两个关于从Azure blob存储读取和写入Python对象的问题将Python数据帧作为CSV写入Azure Blob,python,azure,azure-storage,azure-blob-storage,Python,Azure,Azure Storage,Azure Blob Storage,我有两个关于从Azure blob存储读取和写入Python对象的问题 有人能告诉我如何将Python数据帧作为csv文件直接写入Azure Blob而不在本地存储吗 我尝试使用函数create_blob_from_text和create_blob_from_stream,但都不起作用 将数据帧转换为字符串,并使用create\u blob\u from\u text函数 将文件写入blob,但作为普通字符串写入,而不是csv df_b = df.to_string() block_blob_s
create_blob_from_text
和create_blob_from_stream
,但都不起作用
将数据帧转换为字符串,并使用create\u blob\u from\u text
函数
将文件写入blob,但作为普通字符串写入,而不是csv
df_b = df.to_string()
block_blob_service.create_blob_from_text('test', 'OutFilePy.csv', df_b)
希望它能帮助您。当我将df.to_csv存储在变量中时,它会将其存储在本地目录中,并且该变量不是任何类型。我遗漏了什么吗?请参见此以csv形式将数据发送到blob:
from azure.storage.blob import (
BlockBlobService
)
import pandas as pd
import io
output = io.StringIO()
head = ["col1" , "col2" , "col3"]
l = [[1 , 2 , 3],[4,5,6] , [8 , 7 , 9]]
df = pd.DataFrame (l , columns = head)
print(df)
output = df.to_csv (index_label="idx", encoding = "utf-8")
print(output)
accountName = "***"
accountKey = "***"
containerName = "test1"
blobName = "test3.json"
blobService = BlockBlobService(account_name=accountName, account_key=accountKey)
blobService.create_blob_from_text('test1', 'OutFilePy.csv', output)
from azure.storage.blob import (
BlockBlobService
)
accountName = "***"
accountKey = "***"
containerName = "test1"
blobName = "test3.json"
blobService = BlockBlobService(account_name=accountName, account_key=accountKey)
result = blobService.get_blob_to_text(containerName,blobName)
print(result.content)