pandas .sas7dbat 中的编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38203988/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Encoding in .sas7dbat
提问by rb1992
I am trying to import a sas dataset(.sas7bdat format) using pandas function read_sas
(version 0.17) but it is giving me the following error:
我正在尝试使用 Pandas 函数read_sas
(0.17 版)导入 sas 数据集(.sas7bdat 格式),但它给了我以下错误:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 12: ordinal not in range(128)
UnicodeDecodeError: 'ascii' 编解码器无法解码位置 12 中的字节 0xc2:序号不在范围内 (128)
回答by forest
Use encoding='iso-8859-1'
使用 encoding='iso-8859-1'
pd.read_sas(filepath, format = 'sas7bdat', encoding='iso-8859-1')
回答by rb1992
I was not able to import the file using read_sas but importing the file using sas7bdat has worked.
我无法使用 read_sas 导入文件,但使用 sas7bdat 导入文件已经奏效。
{!pip install sas7bdat
from sas7bdat import SAS7BDAT
f=SAS7BDAT('foo.sas7bdat').to_data_frame()}
回答by S_Dhungel
read_sas from pandas seem to not like encoding = "utf-8". I had a similar problem. Using SAS7BDAT('foo.sas7bdata').to_data_frame() solved the decoding issues of sas files for me.
Pandas的 read_sas 似乎不喜欢 encoding = "utf-8"。我有一个类似的问题。使用 SAS7BDAT('foo.sas7bdata').to_data_frame() 为我解决了 sas 文件的解码问题。