Skip to content

Instantly share code, notes, and snippets.

@sminot
Created June 19, 2019 16:58
Show Gist options
  • Select an option

  • Save sminot/a77ae256f821b13ec4ea253b4dab3657 to your computer and use it in GitHub Desktop.

Select an option

Save sminot/a77ae256f821b13ec4ea253b4dab3657 to your computer and use it in GitHub Desktop.
Read a CSV table from AWS S3
import io
import boto3
import pandas as pd
def read_csv_from_s3(s3_url, s3=None, sep=","):
assert s3_url.startswith("s3://")
bucket_name, key_name = s3_url[5:].split("/", 1)
if s3 is None:
s3 = boto3.client('s3')
retr = s3.get_object(Bucket=bucket_name, Key=key_name)
return pd.read_csv(io.BytesIO(retr['Body'].read()), sep=sep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment