Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: '_csv.reader' object has no attribute 'next()' #2

Open
venkat01 opened this issue Nov 11, 2016 · 8 comments
Open

AttributeError: '_csv.reader' object has no attribute 'next()' #2

venkat01 opened this issue Nov 11, 2016 · 8 comments

Comments

@venkat01
Copy link

I am at lesson 3.3 and rdd_csv_corrrect = rdd_no_header.map(lambda line: csv.reader([line]).next()) is giving an error in .next(). i am using python 3 here.

The error is AttributeError: '_csv.reader' object has no attribute 'next()'

I think this is more of an python2 v/s python3 issue, but need clarification as to how to resolve as this is becoming a show stopper :)

@venkat01
Copy link
Author

The actual error is '_csv.reader' object has no attribute 'next'

I tried googling and it said to use next() and thta is also working

@IlliaKuksenko
Copy link

IlliaKuksenko commented Feb 23, 2018

Hi,
For Python 3.x: Use next(reader) instead of reader.next()

@dharaniviji
Copy link

Worked. Thanks

@dmzlingyin
Copy link

Hi,
For Python 3.x: Use next(reader) instead of reader.next()

thanks,the issue is resolved

@santioktaviana
Copy link

i use this and still error

@santioktaviana
Copy link

#!/usr/bin/env python

import csv

csvr = csv.reader(open('fer2013.csv'))
header = csvr.next(reader)
rows = [row for row in csvr]

trn = [row[:-1] for row in rows if row[-1] == 'Training']
csv.writer(open('test.csv', 'w+')).writerows([header[:-1]] + trn)
print (trn)

tst = [row[:-1] for row in rows if row[-1] == 'PublicTest']
csv.writer(open('test.csv', 'w+')).writerows([header[:-1]] + tst)
print(tst)

tst2 = [row[:-1] for row in rows if row[-1] == 'PrivateTest']
csv.writer(open('testprivate.csv', 'w+')).writerows([header[:-1]] + tst2)
print (tst2)

And this my code

@hemanthasapu
Copy link

#!/usr/bin/env python

import csv

csvr = csv.reader(open('fer2013.csv'))
header = next(csvr)
rows = [row for row in csvr]

trn = [row[:-1] for row in rows if row[-1] == 'Training']
csv.writer(open('test.csv', 'w+')).writerows([header[:-1]] + trn)
print (trn)

tst = [row[:-1] for row in rows if row[-1] == 'PublicTest']
csv.writer(open('test.csv', 'w+')).writerows([header[:-1]] + tst)
print(tst)

tst2 = [row[:-1] for row in rows if row[-1] == 'PrivateTest']
csv.writer(open('testprivate.csv', 'w+')).writerows([header[:-1]] + tst2)
print (tst2)

And this my code

this update works

@shailymishraa
Copy link

Hi,
For Python 3.x: Use next(reader) instead of reader.next()

Thanks for help :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants