DecisionTree笔记

来源:互联网 发布:c编程题及答案 编辑:程序博客网 时间:2024/05/28 09:32
-----------------csvobj.next()-->next(csbobj)---------
AttributeError: '_csv.reader' object has no attribute 'next' 我在使用pyhon3.4运行以下代码时报错:AttributeError:
解决方案:
For version 3.2 and above
Change: csv_file_object.next()
To: next(csv_file_object)


then I get another error:
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
Edit: Figured it out needed to change rb to rt


Finally, it works.
-------------------两个不同列表如何关联:使用range----------


for row in example_reader:
    if example_reader.line_num==1:
        headers=row
        print('header',headers)
        continue




    lable_list.append(row[len(row)-1])
    row_dic = {}
    for i in range(1,len(row)-1):  #这里用range巧妙将header列表和row列表联系起来,
                                 # 组成字典添加到feature_list中
        row_dic[headers[i]]=row[i]
    feature_list.append(row_dic)
print(feature_list)
-------------------列表嵌套字典如何访问:list[0, :]
原创粉丝点击