我正在尝试从谷歌云存储中读取存储为分区的多个 Parquet 文件,并将它们读取为 1 个单个 pandas 数据帧。例如,以下是 gs://path/to/storage/folder/
每个event_date=*
内部都有多个parquet文件
所以目录结构是这样的 -
--gs://path/to/storage/folder/
---event_date=2023-01-01/
---abc.parquet
---def.parquet
---event_date=2023-01-02/
---ghi.parquet
---jkl.parquet
我想将其加载到 pandas 数据框,我使用了下面的代码
import pandas as pd
import gcsfs
from pyarrow import parquet
url = "gs://path/to/storage/folder/event_date=*/*"
fs = gcsfs.GCSFileSystem()
files = ["gs://" + path for path in fs.glob(url)]
print(files)
data = parquet.ParquetDataset(files, filesystem=fs)
multiple_dates_df = data.read().to_pandas()
print(multiple_dates_df.shape)
但我收到以下错误 -
OSError: Passed non-file path: gs://path/to/storage/folder/event_date=2023-01-01/abc.parquet
如何解决这个问题?
最佳答案
pandas 似乎无法读取存储在 gcs 路径下的多个 parquet 文件,在 github 处为此提出了一个错误,该项目仍处于开放状态,可以在那里跟踪进一步的进展。
关于python - 如何将 GCS 中的多个分区 parquet 文件加载到 pandas 数据框中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75529064/