Open Terrygmx opened 6 years ago
I had the same problem. The file is not a binary file. You can try this: from csv import DictReader with open("C:/Users/Administrator/Desktop/data_wrangling/mn.csv", "rt", encoding="utf-8") as mnfile: data_rdr = DictReader(mnfile) data_rows = [d for d in data_rdr] print(data_rows[:5]) with open("C:/Users/Administrator/Desktop/data_wrangling/mn_headers.csv", "rt", encoding="utf-8") as mn_headersfile: header_rdr = DictReader(mn_headersfile) header_rows = [h for h in header_rdr] print(header_rows[:5])
Thank you! I will give it a try!
@jjing11 Thank you for chiming in! <3
Had the same problem, but your @jjing11 solution was helpful Thank you!
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