我在使用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. List转MVC DropDownListFor(SelectList)

    /// <summary> /// List转SelectListItem /// </summary> /// <typeparam name="T" ...

  2. ReportViewer改变图表类型

    /// <summary>    /// 切换成柱状图    /// </summary>    /// <param name="sender"&g ...

  3. LPTHW 笨办法学python 40章 类

    今天读了LPTHW的第40章以后豁然开朗,原来一直愚钝,不太理解类的定义和使用,还有就是不太理解关于self的定义. class MyStuff(object): def __init__(self) ...

  4. IOS OC 多任务定时器 NSRunLoop 管理 NSTimer

    下面有两种做法 1.使用日期组件 NSDateComponents 2.使用NSString 生成一个日期 //  创建一个日历对象 NSCalendar *calendar = [NSCalenda ...

  5. javaEE-----org.springframework.dao.InvalidDataAccessApiUsageException: Write operation

    org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...

  6. C++构造函数与虚表覆盖

    在涉及到虚函数的情况下,C++构造函数的构造顺序为:先调用构造函数,虚表指针初始化,用户代码:如涉及到多重继承情况,初始化顺序为基类.子类(从左至右),假设一个类的继承情况如下图,其初始化顺序为:Po ...

  7. setTimeout的应用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. 【转】DBMS_STATS.GATHER_TABLE_STATS详解

    转自http://blog.itpub.net/26892340/viewspace-721935/ [作用] DBMS_STATS.GATHER_TABLE_STATS统计表,列,索引的统计信息(默 ...

  9. SQL_函数

    五毛叶 — SQL_函数: 如下: 1 SQL_Aggregate函数 AVG() - 返回平均值 COUNT() - 返回行数 FIRST() - 返回第一个记录的值 LAST() - 返回最后一个 ...

  10. mysql数据库性能篇

    慢查询:超过设定时间的SQL语句会被记录到指定文件内 1.观察mysql慢查询默认的时间(默认10秒) show variables like 'long%'; 2.修改慢查询设定时间 set lon ...