【发布时间】:2015-07-15 18:09:49
【问题描述】:
一直在尝试在 python 中获取两个 CSV 文件之间的区别。想通过一系列教程,但多次遇到相同的错误。
import csv
f1 = open ("ted.csv")
oldFile1 = csv.reader(f1, delimiter=',')
oldList1 = list(oldFile1)
f2 = open ("ted2.csv")
newFile2 = csv.reader(f2, delimiter=',')
newList2 = list(newFile2)
f1.close()
f2.close()
output1 = set(row for row in newList2 if row not in oldList1)
output2 = set(row for row in oldList1 if row not in newList2)
print (output2.difference(output1))
回溯可以在下面看到
Traceback (most recent call last):
File "C:/tarts/testmrcsv.py", line 14, in <module>
output1 = set(row for row in newList2 if row not in oldList1)
TypeError: unhashable type: 'list'
我的目标是创建第三个 csv 文件。谢谢
【问题讨论】:
-
difference是一个set方法
标签: python parsing csv python-3.x