Created
November 7, 2018 14:01
-
-
Save jaklinger/1985c2676be31403f9f5da5f55b29741 to your computer and use it in GitHub Desktop.
Read entire content of s3 bucket to pandas dataframe
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 boto3 | |
import pandas as pd | |
from io import BytesIO | |
bucket = "innovation-mapping-general" | |
directory = "nih_all_processed_data/" | |
s3 = boto3.resource('s3') | |
dfs = [] | |
for key in s3.Bucket(bucket).objects.all(): | |
if not key.key.startswith(directory): | |
continue | |
if key.key == directory: | |
continue | |
#print(key.key, str(key.key)) | |
obj = s3.Object(bucket, key.key) | |
with BytesIO(obj.get()['Body'].read()) as bio: | |
df = pd.read_json(bio) | |
dfs.append(df) | |
if len(dfs) > 3: | |
break | |
df = pd.concat(dfs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment