【发布时间】:2018-06-29 18:16:05
【问题描述】:
我目前有 3 个不同的 csv 文件,其中包含一些数据。我想将数据插入到 3 个不同的数组中。这是我目前正在编写的编码
arrayList = []
for index, url in enumerate(urls):
with open('filename{}.csv'.format(index),'r') as f:
for line in f:
while line != '':
arrayList[index].append(line)
我知道代码肯定行不通。有什么办法可以做到吗?
【问题讨论】:
-
有一些很棒的库可以让 CSV 更容易阅读。您要手动执行此操作吗?这个问题有没有可能对您有所帮助? stackoverflow.com/questions/3518778/…
-
while line != '':没有多大意义,我认为if line:更好。此外,您正在尝试索引原始列表,就好像它是嵌套的一样;它不是。您将其定义为 1D -
是的,我意识到,设法使用 csv 模块解决,谢谢顺便说一句! @roganjosh