使用read_sas后如何从b'Text'中以pandas对象类型获取Text?
我正在尝试使用熊猫函数read_sas从SAS的.sas7bdat格式读取数据:
I'm trying to read the data from .sas7bdat format of SAS using pandas function read_sas:
import pandas as pd
df = pd.read_sas('D:/input/houses.sas7bdat', format = 'sas7bdat')
df.head()
我在df数据框中有两种数据类型-float64和object.我对float64数据类型完全满意,因此可以将其自由转换为int,string等. 问题出在对象数据类型上,我可以在包装成这样的df数据框中看到它:
And I have two data types in the df dataframe - float64 and object. I completely satisfied with the float64 datatype, so I can freely convert it to int, string etc. The problem is with object data type, which I can see in the df dataframe wrapped like this:
b'Text'
或类似这样:
b'12345'
代替
Text
或
12345
我无法分别将其转换为字符串或整数或正常"对象数据类型.我也无法使用slice消除b''或替换技术.因此,我无法将列与对象数据类型一起使用. 请告诉我如何摆脱b''.
I can't convert it to string or int respectively or to "normal" object data type. Also I can't eleminate b'' using slice or replace technics. So I'm not able to use columns with the object data type. Please, tell me how can I get rid of b''.
添加此encoding="utf-8"
因此该行如下:
df = pd.read_sas('D:/input/houses.sas7bdat', format = 'sas7bdat', encoding="utf-8")