尝试使用AWS S3的特殊字符读取CSV
我试图使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论