gpt4 book ai didi

python - 将数据帧以羽化格式保存到 S3

转载 作者:行者123 更新时间:2023-12-03 16:52:26 25 4
gpt4 key购买 nike

我有一个数据框,让我们说:

import pandas as pd
df = pd.DataFrame({'a': [1, 4], 'b': [1, 3]})
我想将它作为 Feather 文件保存到 s3,但我找不到一种可行的方法来做到这一点。
我尝试使用 s3bps3fs但他们没有做到这一点。
有什么建议吗?

最佳答案

对我有用的解决方案是

import boto3
import pandas as pd

from io import BytesIO
from pyarrow.feather import write_feather

df = pd.DataFrame({'a': [1, 4], 'b': [1, 3]})

s3_resource = boto3.resource('s3')
with BytesIO() as f:
write_feather(df, f)
s3_resource.Object('bucket-name', 'file_name').put(Body=f.getvalue())

关于python - 将数据帧以羽化格式保存到 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48665232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com