如何从dataframe中的值中删除b'

2024-09-28 23:02:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我从这里读取我的arff数据帧https://archive.ics.uci.edu/ml/machine-learning-databases/00426/如下所示:

from scipy.io import arff
import pandas as pd

data = arff.loadarff('Autism-Adult-Data.arff')
df = pd.DataFrame(data[0])

df.head()

但我的数据帧在所有列的所有值中都有b': enter image description here

如何删除它

当我尝试这种方法时,效果并不理想:

from scipy.io import arff
import pandas as pd

data = arff.loadarff('Autism-Adult-Data.arff')
df = pd.DataFrame(data[0].str.decode('utf-8'))

df.head()

它说AttributeError:'numpy.ndarray'对象没有属性'str' 正如您所看到的,Removing b'' from string column in a pandas dataframe中的.str.decode('utf-8')并没有解决问题

这也不管用:

df.index = df.index.str.encode('utf-8')

A您可以看到它的字符串和数字都是字节对象


Tags: 数据fromioimportarffpandasdfdata