繁体   English   中英

使用Python从S3读取json文件到sagemaker笔记本中

[英]read json file with Python from S3 into sagemaker notebook

我想将S3中的json文件读入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=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。
在这里查看答案: https : //stackoverflow.com/a/47121263

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM