【问题标题】:pandas and azure: DataFrame to_csv blob熊猫和天蓝色:DataFrame to_csv blob
【发布时间】:2019-04-03 16:20:23
【问题描述】:

我想将 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'

  • python 3.7
  • 熊猫 0.23.4
  • azure-blob-storage 1.3.1

【问题讨论】:

    标签: python-3.x pandas azure azure-blob-storage


    【解决方案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()))
    

    【讨论】:

      猜你喜欢
      • 2016-01-17
      • 1970-01-01
      • 2018-05-16
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-08
      • 2019-08-03
      相关资源
      最近更新 更多