我有一个Python3.x的pandas数据框,其中某些列是字符串,表示为字节(类似于Python2.x)
import pandas as pd
df = pd.DataFrame(...)
df
COLUMN1 ....
0 b'abcde' ....
1 b'dog' ....
2 b'cat1' ....
3 b'bird1' ....
4 b'elephant1' ....
使用 df.COLUMN1
按列访问时,我看到 Name: COLUMN1, dtype: object
但是,如果按元素访问,则为“字节”对象。
df.COLUMN1.ix[0].dtype
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'bytes' object has no attribute 'dtype'
我应该如何将它们转换为“普通”的字符串?也就是说,我该如何去掉 b''
前缀?