Load S3 Data into AWS SageMaker Notebook

前端 未结 7 1336
生来不讨喜
生来不讨喜 2020-12-01 07:39

I\'ve just started to experiment with AWS SageMaker and would like to load data from an S3 bucket into a pandas dataframe in my SageMaker python jupyter notebook for analysi

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 08:16

    This code sample to import csv file from S3, tested at SageMaker notebook.

    Use pip or conda to install s3fs. !pip install s3fs

    import pandas as pd
    
    my_bucket = '' #declare bucket name
    my_file = 'aa/bb.csv' #declare file path
    
    import boto3 # AWS Python SDK
    from sagemaker import get_execution_role
    role = get_execution_role()
    
    data_location = 's3://{}/{}'.format(my_bucket,my_file)
    data=pd.read_csv(data_location)
    data.head(2)
    

提交回复
热议问题