Tag Archives: AttributeError: ‘_csv.reader’ object has no attribute ‘next’

AttributeError: ‘_csv.reader’ object has no attribute ‘next’ [How to Solve]

from sklearn.feature_extraction import DictVectorizer
import csv
from sklearn import preprocessing
from sklearn import tree
from sklearn.externals.six import StringIO

#Open CSV file 'rb' is to open a file in binary format for read-only. The file pointer will be placed at the beginning of the file
data = open(r'F:\2. Deep neural network algorithm of the basic essence\machine learning deep neural network learning foundation I 29 lessons\code and material(1)\01DTree\AllElectronics.csv','rb')
reader = csv.reader(data)
header = reader.next()

print(header)
featureList = []
lableList = []

In Python 3, the reader does not have the next() attribute. Instead, use the

header = next(reader)
from sklearn.feature_extraction import DictVectorizer
import csv
from sklearn import preprocessing
from sklearn import tree
from sklearn.externals.six import StringIO

#Open CSV file 'rb' is to open a file in binary format for read-only. The file pointer will be placed at the beginning of the file
data = open(r'F:\2. Deep neural network algorithm of the basic essence\machine learning deep neural network learning foundation I 29 lessons\code and material (1)\01DTree\AllElectronics.csv','rt')
reader = csv.reader(data)
header = next(reader)

print(header)
featureList = []
lableList = []