如何将按列分区的 parquet 写入 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”对象没有属性“_isfilestore”
。
最佳答案
对于 python 3.6+,AWS 有一个名为 aws-data-wrangler 的库,有助于 Pandas/S3/Parquet 之间的集成
安装do;
pip install awswrangler
如果您想将 pandas 数据帧作为分区 parquet 文件写入 S3,请执行;
import awswrangler as wr
wr.s3.to_parquet(
dataframe=df,
path="s3://my-bucket/key/"
dataset=True,
partition_cols=["date"]
)
关于python - 将 pandas parquet 写入分区到 s3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60016439/