我有 2 个这样的文件:
file 1 : file 2 :
col1 col2 col1 col2
john kerry john kerry
adam lord bob abram
joe hitch
我想根据姓氏和名字比较这两个文件,以仅获取一个不包含文件 2 中人员的文件,也就是说:
desired output file :
col1 col2
adam lord
joe hitch
我试过了,但我没有得到正确的输出
import csv
reader1=csv.reader(open('file1.csv', 'r'), delimiter='\t')
reader2=csv.reader(open('file2.csv', 'r'), delimiter='\t')
writer=csv.writer(open('desired_file.csv', 'w'), delimiter=',')
row1 = reader1.next()
row2 = reader2.next()
if (row1[0] == row2[0]) and (row1[1] == row2[1]):
print 'equal'
else:
writer.writerow(row1)
writer.writerow(row2)