【dataquest学习】list
2017-05-18 本文已影响0人
dechuan
1、读取excel数据,输出为list,使用csv_reader
使用官网上的实例
import csv
with open('world_alcohol.csv','rb') as f:
reader = csv.reader(f)
for line in reader:
print(line)
得到的结果:
Error: iterator should return strings, not bytes (did you open the file in text mode?)
最后发现应该这样:
import csv
with open('world_alcohol.csv') as f:
world_alcohol = list(csv.reader(f))
print(world_alcohol)
不能加'rb'?不太理解,是为记。