要在我的本地 Jupyter 笔记本中读取带有 Pandas 的 zip 压缩 csv 文件,我执行:import pandas as pdpd.read_csv('csv_file.zip')但是,在 Watson Studio 中,read_csv()当我将文件名替换为云对象存储流对象时会引发异常。这是我在 Watson Studio 中笔记本的第一个单元格:import typesfrom ibm_botocore.client import Configimport ibm_boto3def __iter__(self): return 0client = ibm_boto3.client(service_name='s3', ibm_api_key_id='...', ibm_auth_endpoint="...", config=Config(signature_version='oauth'), endpoint_url='...')body = client.get_object(Bucket='...', Key='csv_file.zip')['Body']if not hasattr(body, "__iter__"): body.__iter__ = types.MethodType( __iter__, body )现在,当我尝试:import pandas as pddf = pd.read_csv(body)我得到:'utf-8' codec can't decode byte 0xbb in position 0: invalid start byte如果我指定compression='zip':import pandas as pddf = pd.read_csv(body, compression='zip')消息是:'StreamingBody' object has no attribute 'seek'read_csv()在 Watson Studio 中是否有直接压缩文件的方法,而无需显式编写解包代码?(该pd.__version__是0.21.0在两种环境中。)
添加回答
举报
0/150
提交
取消