使用Python将json文件从S3读入sagemaker笔记本
我想将一个json文件从S3读入sagemaker笔记本 我可以用这段代码对熊猫执行此操作,并且不会出错:使用Python将json文件从S3读入sagemaker笔记本,python,json,amazon-s3,amazon-sagemaker,Python,Json,Amazon S3,Amazon Sagemaker,我想将一个json文件从S3读入sagemaker笔记本 我可以用这段代码对熊猫执行此操作,并且不会出错: import json import pandas as pd import boto3 prefix_source = 'folder' s3 = boto3.resource('s3') my_bucket_source = s3.Bucket('bucket_source') for obj in my_bucket_source.objects.filter(Prefix=
import json
import pandas as pd
import boto3
prefix_source = 'folder'
s3 = boto3.resource('s3')
my_bucket_source = s3.Bucket('bucket_source')
for obj in my_bucket_source.objects.filter(Prefix=prefix_source):
data_location = 's3://{}/{}'.format(obj.bucket_name, obj.key)
data = pd.read_json(data_location, lines = True )
display(data.head())
但是我不想使用熊猫,我想使用Python
我试过这个密码
for obj in my_bucket_source.objects.filter(Prefix=prefix_source):
data_location = 's3://{}/{}'.format(obj.bucket_name, obj.key)
with open(data_location, 'r') as f:
array = json.load(f)
display(array)
我得到了这个错误:
IOError:[Errno 2]没有这样的文件或目录Json.load()需要本地文件系统路径“/”,而不是“s3://”URI。请参阅此处的答案:尝试使用array=json.loads(file.read())