这是ibm云在我上传数据集时自动生成的代码,我尝试了编码=‘拉丁语-1’,但它还是给了我错误。
import os, types
import pandas as pd
from botocore.client import Config
import ibm_boto3
def __iter__(self): return 0
if os.environ.get('RUNTIME_ENV_LOCATION_TYPE') == 'external':
endpoint_3660ea30b8c954806ac4 = 'https://s3.us.cloud-object-storage.appdomain.cloud'
else:
endpoint_3660ea30b8c954806ac4 = 'https://s3.private.us.cloud-object-storage.appdomain.cloud'
client_3660ea30b8c954806ac4 = ibm_boto3.client(service_name='s3',
ibm_api_key_id='xjHcqdBlY9iaaD7qu17e6-njKJPFSdGWk4d',
ibm_auth_endpoint="https://iam.cloud.ibm.com/oidc/token",
config=Config(signature_version='oauth'),
endpoint_url=endpoint_3660ea30b8c954806ac4)
body = client_3660ea30b8c954806ac4.get_object(Bucket='spamdetectionmodel-donotdelete-pr-mt98rs41prv05c',Key='spam.csv')['Body']
# add missing __iter__ method, so pandas accepts body as file-like object
if not hasattr(body, "__iter__"): body.__iter__ = types.MethodType( __iter__, body )
df_data_1 = pd.read_csv(body)
df_data_1.head()错误:
'utf-8‘编解码器无法解码位置135-136的字节:无效的连续字节
发布于 2021-08-09 05:33:41
您是否尝试过更改“熊猫encoding”设置,请尝试如下:
df_data_1 = pd.read_csv(body, encoding='utf-8')或者另一种选择:
df_data_1 = pd.read_csv(body, encoding='ISO-8859-1')阅读encoding设置,下面帮助我解决这样的错误:
UnicodeDecodeError when reading CSV file in Pandas with Python
https://stackoverflow.com/questions/68707045
复制相似问题