2

I have csv files in S3 bucket, I want to use those to train model in sagemaker.

using this code but it gives an error (file not found)

import boto3
import pandas as pd
region = boto3.Session().region_name
train_data_location = 's3://taggingu-{}/train.csv'.format(region)
df=pd.read_csv(train_data_location, header = None)
print df.head

What can be the solution to this ?

Utsav Shukla
  • 47
  • 2
  • 8
  • Possible duplicate of [Load S3 Data into AWS SageMaker Notebook](https://stackoverflow.com/questions/48264656/load-s3-data-into-aws-sagemaker-notebook) – Hack-R Apr 25 '19 at 16:36

2 Answers2

4

Not sure but could this stackoverflow answer it? Load S3 Data into AWS SageMaker Notebook

To quote @Chhoser:

import boto3
import pandas as pd
from sagemaker import get_execution_role

role = get_execution_role()
bucket='my-bucket'
data_key = 'train.csv'
data_location = 's3://{}/{}'.format(bucket, data_key)

pd.read_csv(data_location)
erncyp
  • 1,649
  • 21
  • 23
0

You can use AWS SDK for Pandas, a library that extends Pandas to work smoothly with AWS data stores.

import awswrangler as wr
df = wr.s3.read_csv("s3://bucket/file.csv")

Most notebook kernels have it, if missing it can be installed via pip install awswrangler.

Theofilos Papapanagiotou
  • 5,133
  • 1
  • 18
  • 24