美文网首页
【dataquest学习】list

【dataquest学习】list

作者: dechuan | 来源:发表于2017-05-18 09:38 被阅读0次

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'?不太理解,是为记。

相关文章

网友评论

      本文标题:【dataquest学习】list

      本文链接:https://www.haomeiwen.com/subject/razjxxtx.html