首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型错误参数%1需要是迭代器

类型错误参数%1需要是迭代器
EN

Stack Overflow用户
提问于 2018-02-21 06:04:39
回答 1查看 1.4K关注 0票数 1

我目前正在尝试将数据从我的filteredData.csv复制到我的平均2016.csv,这是我已经完成的,但当我尝试拆分数据时,我得到了

代码语言:javascript
复制
File 
"U:/CISP253/Final/test", line 9, in <module>
    readCSV = csv.reader(csvfile, delimiter=',')
TypeError: argument 1 must be an iterator
>>> 

都是我的错。

代码语言:javascript
复制
import shutil
import csv
import collections
with open("filteredData.csv", "wb") as csvfile:
    csvfile.close()

with open("average2016.csv", "w") as csvfile2:
    shutil.copyfile('filteredData.csv', 'average2016.csv')
    readCSV = csv.reader(csvfile2, delimiter=',')
    result = collections.defaultdict(list)
    for row in readCSV:
       year = row[1].split("-")[0]
       result[year].append(row)

    csvfile2.close()

我对readCSV = csv.reader( csvfile2,delimiter=',')进行了必要的更改,如前所述将csvfile转换为csvfile2。另外,这是拆分日期的最好方法吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-21 06:07:10

你忘了换成csvfile2

代码语言:javascript
复制
with open("average2016.csv", "w") as csvfile2:
    shutil.copyfile('filteredData.csv', 'average2016.csv')
    readCSV = csv.reader(csvfile2, delimiter=',')
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48895003

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档