尝试使用AWS S3的特殊字符读取CSV

发布于 2025-01-30 07:13:11 字数 661 浏览 2 评论 0原文

我试图使用AWS lambda从我的S3上读取CSV,但是CSV有来自巴西葡萄牙字母的特殊字符。

def rentabilidade_sintetica():

s3_client = boto3.client('s3')

bucket_name = "bucket-my"
s3_file_name = "historico/Rentabilidade Sintetica1.csv"
resp = s3_client.get_object(Bucket=bucket_name, Key=s3_file_name)
df_s3_data = pd.read_csv(resp['Body'], sep=';')

因此,我会收到以下错误:

“ errormessage”:“'utf-8'编解码器无法在位置4:数据的意外末端中解码字节0xf3,

“ errortype”:“ unicodeDeDecodeError”,

当我更改特殊情况时CSV文件中的字符,代码有效。

因此,我尝试在read_csv上指定编码参数:

df_s3_data = pd.read_csv(resp['Body'], sep=';', encoding='cp860')

但是它给了我同样的错误。

您还有其他阅读的方法吗?

Im trying to read a csv from my bucket on S3 using AWS Lambda, but the csv have special characters from brazillian portuguese alphabet.

def rentabilidade_sintetica():

s3_client = boto3.client('s3')

bucket_name = "bucket-my"
s3_file_name = "historico/Rentabilidade Sintetica1.csv"
resp = s3_client.get_object(Bucket=bucket_name, Key=s3_file_name)
df_s3_data = pd.read_csv(resp['Body'], sep=';')

Because of that, i get the following error:

"errorMessage": "'utf-8' codec can't decode byte 0xf3 in position 4: unexpected end of data",

"errorType": "UnicodeDecodeError",

When I changed the special characters in the csv files, the code worked.

So I tried to specify the encoding parameter at read_csv:

df_s3_data = pd.read_csv(resp['Body'], sep=';', encoding='cp860')

but it gave me the same error.

Do you have any other method to read this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文