所以我有兩個csv文件。 Book1.csv
有更多的數據比similarities.csv
所以我想拔出排在Book1.csv
是做similarities.csv
不發生這裏是我到目前爲止比較兩個csv文件中的內容
with open('Book1.csv', 'rb') as csvMasterForDiff:
with open('similarities.csv', 'rb') as csvSlaveForDiff:
masterReaderDiff = csv.reader(csvMasterForDiff)
slaveReaderDiff = csv.reader(csvSlaveForDiff)
testNotInCount = 0
testInCount = 0
for row in masterReaderDiff:
if row not in slaveReaderDiff:
testNotInCount = testNotInCount + 1
else :
testInCount = testInCount + 1
print('Not in file: '+ str(testNotInCount))
print('Exists in file: '+ str(testInCount))
然而,結果是
Not in file: 2093
Exists in file: 0
我知道這是不正確的,因爲至少Book1.csv
的前16個條目不存在於similarities.csv
不是全部。我究竟做錯了什麼?