如何从 Azure blob 存储将 parquet 文件读入 pandas

use*_*008 5 python azure parquet jupyter

我需要在运行 Python 3 内核的 Jupyter 笔记本上下文中从 Azure blob 存储读取和写入 parquet 文件。

我看到了严格使用 parquet 文件和 python 的代码以及用于抓取/写入 Azure blob 存储的其他代码,但还没有将它们组合在一起的代码。

这是我正在使用的一些示例代码:

from azure.storage.blob import BlockBlobService block_blob_service = BlockBlobService(account_name='testdata', account_key='key-here') block_blob_service.get_blob_to_text(container_name='mycontainer', blob_name='testdata.parquet')

最后一行抛出一个与编码相关的错误。我玩过storefact但还不够。

谢谢你的帮助

小智 0

要访问该文件,您需要首先访问 azure blob 存储。

storage_account_name = "your storage account name"
storage_account_access_key = "your storage account access key"
Run Code Online (Sandbox Code Playgroud)

将镶木地板文件的路径读取到变量中

commonLOB_mst_source = "Parquet file path"
file_type = "parquet"
Run Code Online (Sandbox Code Playgroud)

连接到 blob 存储

spark.conf.set(
  "fs.azure.account.key."+storage_account_name+".blob.core.windows.net",
  storage_account_access_key)
Run Code Online (Sandbox Code Playgroud)

将 Parquet 文件读入数据帧

df = spark.read.format(file_type).option("inferSchema", "true").load(commonLOB_mst_source)
Run Code Online (Sandbox Code Playgroud)