AttributeError: '_csv.reader' object has no attribute 'next'
我在使用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'的更多相关文章
- 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 ...
- 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 ...
- keras报错:AttributeError: '_thread._local' object has no attribute 'value'
需求是使用pyqt5中的槽函数运行keras模型训练,为了不让工具在模型训练的过程中出现假死的现象,于是把训练操作放到单独的线程中运行,于是问题来了,训练操作在主线程运行时正常,但是界面假死,假若训练 ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
- AttributeError: 'list' object has no attribute 'write_pdf'
我在可视化决策树,运行以下代码时报错:AttributeError: 'list' object has no attribute 'write_pdf' 我使用的是python3.4 from sk ...
- attributeError:'module' object has no attribute ** 解决办法
写了一个小脚本,执行的时候报错: Traceback (most recent call last): File "F:/test/qrcode.py", line 109, in ...
- AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'
/*************************************************************************** * AttributeError: 'modu ...
- AttributeError: 'dict_values' object has no attribute 'translate'
/***************************************************************************************** * Attribu ...
- python3 AttributeError: 'NoneType' object has no attribute 'split'
from wsgiref.simple_server import make_server def RunServer(environ, start_response): start_response ...
随机推荐
- MVC 架构
MVC 模式是一种严格实现应用程序个部分隔离的框架模式.这种"隔离"也叫"分离关注点" 通俗名称:"松耦合" 松耦合的应用程序价格设计方式, ...
- TeeChart常用编程语句汇总(C#)
我用的是C# 从网上看到资料拷贝过来备忘,共同学习下: 设置chart标题:axTChart1.Header.Text.Add("标题"); 修改标题:axTChart1.Hea ...
- Java EE 编程中路径
版权声明:未经博主允许,不得转载 首先我们要限定一个范围,是一个项目,或是以个访问地址..就先以一个项目为限定的范围 前述: 学过物理学的都知道相对运动和绝对运动, 虽然是相似的概念,但这里的要简单得 ...
- webclient的简单实用
这是我在项目中调用别人写好的接口口是使用的1.简单的url传参 List<ArticleModel> result = new List<ArticleModel>(); st ...
- C++的学习资源
本文总结了几个好的C++网站,以及C++方面的经典书籍.所列书籍或标准可以到这里找找电子版. wikipedia关于C++有关条目,注意看后面“参考文献”和“外部链接”: C++ programmin ...
- rtmp转m3u8
不是所有的地址改成这样都能播 需要自己测试 先说一下rtmp的其中rtmp的常见的差不多是3种 1.一种是wowza服务器的 比如这个地址rtmp://116.55.245.135:8096/live ...
- 从AutoCAD和.NET开始
引自并参考Kean's blog:http://through-the-interface.typepad.com/through_the_interface/2006/07/getting_star ...
- UE4 VR 模式全屏 4.13
以前写了一个4.11版本全屏,高版本的没用所以也不清楚情况,最近出了4.13,刚好新项目要用上打包出来以后发现,控制台命令fullscreen没有用了, 被stereo on 替代,但是还是没有全屏, ...
- test「Python」流程&中文
#例1 text='dShArpen骑草泥马在马勒隔壁玩Python时看到一群SB绿茶婊在逗逼,马上的他马上吓尿了' iftext = '马' for letter in text.decode('u ...
- JavaScript,DOM经典基础面试题
JavaScript的数据类型 JavaScript的数据类型可以分为原始类型和对象类型 原始类型包括string,number和Boolean三种,其中字符串是使用一对单引号或者一堆双引号括起来的任 ...