【发布时间】:2025-12-18 12:15:01
【问题描述】:
我正在尝试读取存储在 s3 存储桶中的分区 parquet 目录。
为了这个问题,我们将桶称为bucket。存储桶有一个文件夹,该文件夹具有基于年/月/日/小时的后续分区。
因此,如果要访问 .parquet 文件,则 url 将是:
s3://bucket/folder/year/month/day/hour
我尝试阅读它,就像阅读任何其他镶木地板文件一样。我最近一直在和他们一起工作。但是,到目前为止,我还没有尝试读取分区文件。
我在下面包含了我的示例代码:
import s3fs
import pandas as pd
import boto3
# Creating an S3 Filesystem (Only required when using S3)
s3 = s3fs.S3FileSystem()
s3_path = "s3://bucket"
directory = 'folder'
# Loading Files (S3)
data = pq.ParquetDataset(f'{s3_path}/{directory}', filesystem = s3).read_pandas().to_pandas()
这是我使用过的流程,我知道它适用于一般镶木地板文件。现在,我得到的错误是这样的:
ValueError: Directory name did not appear to be a partition: 2019
我已经尝试深入了解2019,因为我认为第一级只有2019 作为文件夹,所以它可能认为它是子目录而不是分区。
然后路径看起来像s3://bucket/folder/2019
但是,这给了我以下类似的错误:
ValueError: Directory name did not appear to be a partition: 05
我也尝试过使用fastparquet,遵循这个问题的方法:How to read partitioned parquet files from S3 using pyarrow in python
那也没用。如果我尝试使用上述问题答案中的all_paths_from_s3 打印文件列表,它会给我一个空白列表[]。
【问题讨论】:
标签: python amazon-web-services amazon-s3 parquet pyarrow