使用read_sas后如何从b'Text'中以pandas对象类型获取Text? [英] How to get Text from b'Text' in the pandas object type after using read_sas?

查看:233
本文介绍了使用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")

这篇关于使用read_sas后如何从b'Text'中以pandas对象类型获取Text?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆