Created
June 19, 2019 16:58
-
-
Save sminot/a77ae256f821b13ec4ea253b4dab3657 to your computer and use it in GitHub Desktop.
Read a CSV table from AWS S3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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