【问题标题】:Load Pandas Dataframe to S3 passing s3_additional_kwargs通过 s3_additional_kwargs 将 Pandas Dataframe 加载到 S3
【发布时间】:2020-05-29 13:38:20
【问题描述】:

请原谅我在这方面的无知/缺乏知识!

我希望将数据帧上传到 S3,但我需要传递 'ACL':'bucket-owner-full-control'。

import pandas as pd
import s3fs

fs = s3fs.S3FileSystem(anon=False, s3_additional_kwargs={'ACL': 'bucket-owner-full-control'})
df = pd.DataFrame()
df['test'] = [1,2,3]
df.head()

df.to_parquet('s3://path/to/file/df.parquet', compression='gzip')

我已经设法解决了这个问题,然后将其加载到 Pyarrow 表中,加载如下:

import pyarrow.parquet as pq

table = pa.Table.from_pandas(df)

pq.write_to_dataset(table=table, 
                    root_path='s3://path/to/file/',
                    filesystem=fs) 

但这感觉很hacky,我觉得在第一个示例中必须有一种方法可以通过ACL。

【问题讨论】:

    标签: python pandas dataframe amazon-s3


    【解决方案1】:

    对于 Pandas 1.2.0,这里提到了 storage_options

    如果你被 Pandas

    storage_options = dict(anon=False, s3_additional_kwargs=dict(ACL="bucket-owner-full-control"))
    
    import s3fs
    fs = s3fs.S3FileSystem(**storage_options)
    df.to_parquet('s3://foo/bar.parquet', filesystem=fs)
    

    【讨论】:

      【解决方案2】:

      你可以做到的:

      pd.to_parquet('name.parquet',storage_options={"key":xxxxx,"secret":gcp_secret_access_key,'xxxxx':{'ACL': 'bucket-owner-full-control'}})
      

      【讨论】:

        猜你喜欢
        • 2017-04-27
        • 2013-10-06
        • 2017-07-16
        • 1970-01-01
        • 1970-01-01
        • 2016-06-30
        • 2016-09-26
        • 2018-06-25
        相关资源
        最近更新 更多