我在IBM云中有一个云对象存储和一个存储桶。存储桶中有.wav文件,我已经在watson studio中建立了到我的项目的连接,我还添加了数据资产。但是我无法将数据插入到python jupyter笔记本中。我只得到了在查找添加数据选项中插入凭据,而不是作为流对象的数据。前几天我经常这样做。我使用的是精简版,我的账户免费试用一个月,有效期到2019年8月12日
发布于 2019-08-26 21:09:02
该选项将再次启用,同时您可以使用下面的代码片段将.wav文件作为StreamingBody读取
import types
import pandas as pd
from botocore.client import Config
import ibm_boto3
def __iter__(self): return 0
os_client= ibm_boto3.client(service_name='s3',
ibm_api_key_id='<IBM_API_KEY_ID>',
ibm_auth_endpoint="<IBM_AUTH_ENDPOINT>",
config=Config(signature_version='oauth'),
endpoint_url='<ENDPOINT>')
# Your data file was loaded into a botocore.response.StreamingBody object.
# Please read the documentation of ibm_boto3 and pandas to learn more about the possibilities to load the data.
# ibm_boto3 documentation: https://ibm.github.io/ibm-cos-sdk-python/
# pandas documentation: http://pandas.pydata.org/
streaming_body_1 = os_client.get_object(Bucket='<BUCKET>', Key='myfile.wav')['Body']
# add missing __iter__ method, so pandas accepts body as file-like object
if not hasattr(streaming_body_1, "__iter__"): streaming_body_1.__iter__ = types.MethodType( __iter__, streaming_body_1 )您可以在此stackoverflow answer中了解有关从对象存储读取对象到运行时本地文件系统的更多详细信息
https://stackoverflow.com/questions/57365400
复制相似问题