The code reading csv data and using list comprehension in this chapter gets an error in my Windows:
"Error: iterator should return strings, not bytes (did you open the file in
text mode?)"
BTW, the code is:
`from csv import DictReader
data_rdr = DictReader(open(r'F:\Learn\python data wrangling\data-wrangling-master\data\unicef\mn.csv','rb'))
header_rdr = DictReader(open(r'F:\Learn\python data wrangling\data-wrangling-master\data\unicef\mn_headers.csv','rb'))
data_rows = [d for d in data_rdr]
header_rows = [h for h in header_rdr]
print(data_rows[:5])
print(header_rows[:5])`
I searched in stackoverflow, which says
You need to wrap the file in a io.TextIOWrapper() instance, and you need to figure out the encoding
Is this correct?
I am using Python 3.5.2
The code reading csv data and using list comprehension in this chapter gets an error in my Windows:
"Error: iterator should return strings, not bytes (did you open the file in
text mode?)"
BTW, the code is:
`from csv import DictReader
data_rdr = DictReader(open(r'F:\Learn\python data wrangling\data-wrangling-master\data\unicef\mn.csv','rb'))
header_rdr = DictReader(open(r'F:\Learn\python data wrangling\data-wrangling-master\data\unicef\mn_headers.csv','rb'))
data_rows = [d for d in data_rdr]
header_rows = [h for h in header_rdr]
print(data_rows[:5])
print(header_rows[:5])`
I searched in stackoverflow, which says
Is this correct?
I am using Python 3.5.2