虽然pandas能够通过to_csv保存文件到S3,但是to_json报错FileNotFound
以下方式能够解决该问题:
# save to s3
bucket = "bucket"
file_path = "path/to/file"
jsonBuffer = io.StringIO()
df.to_json(jsonBuffer, orient="records", lines=True)
session = boto3.Session()
s3 = session.resource('s3')
s3.Object(bucket, file_path).put(Body=jsonBuffer.getvalue())