【发布时间】:2021-05-04 08:59:26
【问题描述】:
你好 stackoverflow 社区,
我在读取镶木地板文件时遇到了一些问题。在我使用 Python 将 Parquet 文件上传到 Azure Data Lake gen 2 后,问题就开始了。
我使用的是微软官方文档:https://docs.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-python
除了认证,这部分:
def upload_file_to_directory():
try:
file_system_client = service_client.get_file_system_client(file_system="my-file-system")
directory_client = file_system_client.get_directory_client("my-directory")
file_client = directory_client.create_file("uploaded-file.txt")
local_file = open("C:\\file-to-upload.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))
except Exception as e:
print(e)
当我使用代码上传一个小的 csv 文件时,它工作得很好。 csv 文件已上传,当我下载文件时,我可以毫无问题地打开它。
如果我将相同的数据框转换为一个小的 parquet 文件并上传该文件,则上传工作正常。但是当我下载文件并尝试打开它时,我收到错误消息:
ArrowInvalid:在页脚中找不到 Parquet 魔术字节。文件已损坏,或者这不是 parquet 文件。
如果我直接读取 Parquet 字段而不上传,它可以正常工作。
有没有人建议我如何修改代码以免破坏我的镶木地板文件?
谢谢!
【问题讨论】:
标签: python pandas dataframe parquet azure-data-lake