Skip to content

Instantly share code, notes, and snippets.

@yassineAlouini
Created February 28, 2019 15:58
Show Gist options
  • Save yassineAlouini/384d4fafedadd8b78685aafc82952354 to your computer and use it in GitHub Desktop.
Save yassineAlouini/384d4fafedadd8b78685aafc82952354 to your computer and use it in GitHub Desktop.
Save DataFrame to S3 as a CSV with bz2 compression
import s3fs
import pandas as pd
import bz2file
s3 = s3fs.S3FileSystem()
df = pd.DataFrame() # Replace with your DataFrame
dest_s3_key = "" # Where to save in S3
with s3.open(dest_s3_key, 'wb') as dest_file:
with bz2file.open(dest_file, 'wb') as compressed_file:
df.to_csv(compressed_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment