1from io import StringIO # python3; python2: BytesIO
2import boto3
3
4bucket = 'my_bucket_name' # already created on S3
5csv_buffer = StringIO()
6df.to_csv(csv_buffer)
7s3_resource = boto3.resource('s3')
8s3_resource.Object(bucket, 'df.csv').put(Body=csv_buffer.getvalue())
9