我想将python pandas DataFrame存储到Azure,但是Jay Gong(Python 2.7)的解决方案给了我错误:
from azure.storage.blob import BlockBlobService
service = BlockBlobService(
account_name=STORAGE_ACCOUNT_NAME,
account_key=STORAGE_ACCOUNT_KEY
)
with io.StringIO() as stream:
df.to_csv(stream, encoding="utf-8")
service.create_blob_from_text('containert', 'example.txt', stream)
返回:
AttributeError:'_io.StringIO'对象没有属性'encode'
答案 0 :(得分:1)
这有效,但并不十分优雅:
with io.StringIO() as streamio:
df.to_csv(streamio, encoding = "utf-8", index=False)
streamio.seek(0)
service.create_blob_from_text('containert', 'example.txt', "".join(streamio.readlines()))