AttributeError:'Series'对象没有属性'Id'

时间:2016-11-01 10:20:00

标签: python series

我正在尝试创建恶意软件分类器,我遇到了错误

 AttributeError: 'Series' object has no attribute 'Id. Not sure of the error.

Traceback (most recent call last):
File"C:/Users/Afiqmatters/PycharmProjects/MajorProject/feature_extraction.py", line 23, in <module>
rids = [mids.loc[i].Id for i in rchoice]
 File "C:\Users\Afiqmatters\Miniconda\lib\site-packages\pandas\core\generic.py", line 2744, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'Id'

以下是我遇到错误的代码。

rs = Random()
rs.seed(1)

trainLabels = pd.read_csv('trainLabels.csv')
#print trainLabels

fids = []

opd = pd.DataFrame()

for label in range(1,10):
    mids = trainLabels[trainLabels.Class == label]
    mids = mids.reset_index(drop=True)
#print mids
rchoice = [rs.randint(0, len(mids) - 1) for i in range(10)]
print len
#print rchoice
rids = [mids.loc[i].Id for i in rchoice]

错误发生在rids = [mids.loc [i] .Id for i in rchoice]中,我不确定错误。

存储在trainLabels.csv

中的样本
Id                                   Class
0A32eTdBKayjCWhZqDOQ                    2

1 个答案:

答案 0 :(得分:0)

在此上下文中,

mids.loc[i]是一个“系列”对象,详细内容为here

此对象类型没有属性Series.Id,因此您就会看到此错误。

你的意思是在对象上调用内置函数id( )吗?

rids = [id(mids.loc[i]) for i in rchoice]