在python中从url读取feather文件

2024-10-01 07:45:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用s3的api网关代理来读取feather文件。下面是我正在使用的代码的最简单形式

import pandas as pd

s3_data=pd.read_feather('https://<api_gateway>/<bucket_name/data.feather>')

这会产生一个错误-

   reader = _feather.FeatherReader(source, use_memory_map=memory_map)
  File "pyarrow\_feather.pyx", line 75, in pyarrow._feather.FeatherReader.__cinit__
  File "pyarrow\error.pxi", line 143, in pyarrow.lib.pyarrow_internal_check_status
  File "pyarrow\error.pxi", line 114, in pyarrow.lib.check_status
OSError: Verification of flatbuffer-encoded Footer failed.

如果我把feather文件保存在我的本地文件中,并像下面那样阅读,那么一切都很好

s3_data=pd.read_feather("file://localhost//C://Users//<Username>//Desktop//data.feather")

我该怎么做


Tags: 文件inapimapreaddatas3line
1条回答
网友
1楼 · 发布于 2024-10-01 07:45:46

可能网关代理需要执行一些重定向,这会导致它失败。我会这样做:

from s3fs import S3FileSystem

fs = S3FileSystem(anon=True)
with fs.open("<bucket>/data.feather") as f:
    df = pd.read_feather(f)

s3fs是Dask的一部分。还可以使用其他类似的层

PS:如果您使用feather进行长期数据存储,Apache Arrow项目建议不要使用它(feather的维护者)。你可能应该用拼花地板

相关问题 更多 >