[英]Removing b'' from string column in a pandas dataframe
您正在使用字节字符串。 您可能会考虑str.decode
:
data['class'] = data['class'].str.decode('utf-8')
进一步说明:
df = pd.DataFrame([b'123']) # create dataframe with b'' element
现在我们可以打电话
df[0].str.decode('utf-8') # returns a pd.series applying decode on str succesfully
df[0].decode('utf-8') # tries to decode the series and throws an error
基本上,您使用.str()所做的就是将其应用于所有元素。 也可以这样写:
df[0].apply(lambda x: x.decode('utf-8'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.