我在使用pyhon3.4运行以下代码时报错:AttributeError: '_csv.reader' object has no attribute 'next'

import csv
import numpy as np
with open('C:/Users/Administrator/Desktop/data/titanic.csv', 'rb') as csvfile:
titanic_reader = csv.reader(csvfile, delimiter=',', quotechar = '"')
# Header contains feature names
row = titanic_reader.next()
feature_names = np.array(row) # Load dataset, and target classes
titanic_X, titanic_y = [], []
for row in titanic_reader:
titanic_X.append(row)
titanic_y.append(row[2]) #The target value is "survived"
titanic_X = np.array(titanic_X)
titanic_y = np.array(titanic_y)

解决方案:

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.

REF.

[1]https://www.kaggle.com/c/titanic/forums/t/4937/titanic-problem-with-getting-started-with-python

AttributeError: '_csv.reader' object has no attribute 'next'的更多相关文章

  1. AttributeError: 'sys.flags' object has no attribute 'utf8_mode'

    AttributeError: 'sys.flags' object has no attribute 'utf8_mode' pycharm工程的py版本是3.6,结果即使使用py3.7编译后的py ...

  2. AttributeError: 'cx_Oracle.Cursor' object has no attribute 'numbersAsStrings'

    转载自:https://www.wengbi.com/thread_77579_1.html 最近在本地搭建Django开发环境,Django 1.11,python 2.7.11,数据库Oracle ...

  3. keras报错:AttributeError: '_thread._local' object has no attribute 'value'

    需求是使用pyqt5中的槽函数运行keras模型训练,为了不让工具在模型训练的过程中出现假死的现象,于是把训练操作放到单独的线程中运行,于是问题来了,训练操作在主线程运行时正常,但是界面假死,假若训练 ...

  4. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

  5. AttributeError: 'list' object has no attribute 'write_pdf'

    我在可视化决策树,运行以下代码时报错:AttributeError: 'list' object has no attribute 'write_pdf' 我使用的是python3.4 from sk ...

  6. attributeError:'module' object has no attribute ** 解决办法

    写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...

  7. AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'

    /*************************************************************************** * AttributeError: 'modu ...

  8. AttributeError: 'dict_values' object has no attribute 'translate'

    /***************************************************************************************** * Attribu ...

  9. python3 AttributeError: 'NoneType' object has no attribute 'split'

    from wsgiref.simple_server import make_server def RunServer(environ, start_response): start_response ...

随机推荐

  1. 启发式搜索A*算法

    A* 寻路算法 (2011-02-15 10:53:11) 转载▼ 标签: 游戏 分类: 算法 概述 虽然掌握了 A* 算法的人认为它容易,但是对于初学者来说, A* 算法还是很复杂的. 搜索区域(T ...

  2. UItableVIew初探

    UItableView style/* //普通  UITableViewStylePlain,   //分组  UITableViewStyleGrouped*/ //表格视图    UITable ...

  3. extjs_button

    在网页中,填写的内容都在form(表单)中显示,要交互就要用到按钮.所以,今天试了一下按钮,但不清楚的是js中定义的按钮能显示在页面,但怎样响应php代码呢?实际效果就是点击按钮后,通过什么方式调出数 ...

  4. [转]恢复 git reset -hard 的误操作

    转帖:http://hi.baidu.com/configuration/item/97fddeea252818d0eb34c964 有时候使用Git工作得小心翼翼,特别是涉及到一些高级操作,例如 r ...

  5. Jquery面试题

    1.改变一个标签中的属性的值? 分为两种情况: 改变style中的css样式属性值: $("ID").css({color:red,font-size:30px....});   ...

  6. xxxxxxx

    int c; int b; bool h;

  7. 配置JDK环境变量,与各步骤的意义

    配置JDK环境变量 1,新建变量名:JAVA_HOME,变量值:C:\Program Files\Java\jdk1.7.0                   (变量值为jdk安装路径) 2,打开P ...

  8. Search for a Range

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  9. Python使用re模块正则式的预编译及pickle方案

    项目上线要求当中有言论和昵称的过滤需求, 客户端使用的是python脚本, python脚本中直接利用re模块来进行正则匹配, 一开始的做法是开启游戏后, 每帧编译2条正则式, 无奈运营需求里面100 ...

  10. 跟我学Windows Azure 一 创建Windows Azure试用账号

    我在网上看了很多教程,很大部分都是申请的是国外或者是香港的试用账号,而国内是由世纪互联所代理的,他的申请方式与VS2013的部署设置或多或少还是有些出入,这里我先跟大家一起过一下,在国内如何申请一个w ...