我目前正在尝试将数据从我的filteredData.csv复制到我的平均2016.csv,这是我已经完成的,但当我尝试拆分数据时,我得到了
File
"U:/CISP253/Final/test", line 9, in <module>
readCSV = csv.reader(csvfile, delimiter=',')
TypeError: argument 1 must be an iterator
>>> 都是我的错。
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。另外,这是拆分日期的最好方法吗?
谢谢
发布于 2018-02-21 06:07:10
你忘了换成csvfile2
with open("average2016.csv", "w") as csvfile2:
shutil.copyfile('filteredData.csv', 'average2016.csv')
readCSV = csv.reader(csvfile2, delimiter=',')https://stackoverflow.com/questions/48895003
复制相似问题