簡體   English   中英

將 Pandas Parquet 分區為 s3

[英]write pandas parquet partitioned into s3

如何將按列分區的鑲木地板寫入 s3? 我想:

def write_df_into_s3(df, bucket_name, filepath, format="parquet"):
    buffer = None
    hook = S3Hook()

    if format == "parquet":
        buffer = BytesIO()
        df.to_parquet(buffer, index=False, partition_cols=['date'])
    else:
        raise Exception("Format not implemented!")

    hook.load_bytes(buffer.getvalue(), filepath, bucket_name)

    return f"s3://{bucket_name}/{filepath}"

但是我收到一個錯誤'NoneType' object has no attribute '_isfilestore'

對於 python 3.6+,AWS 有一個名為 aws-data-wrangler 的庫,可以幫助 Pandas/S3/Parquet 之間的集成

安裝做;

pip install awswrangler

如果要將 Pandas 數據幀作為分區的鑲木地板文件寫入 S3,請執行;

import awswrangler as wr
wr.s3.to_parquet(
    dataframe=df,
    path="s3://my-bucket/key/"
    dataset=True,
    partition_cols=["date"]
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM