我正在尝试比较 2 个 csv 之间特定列的值。我尝试了以下代码。但是,我没有得到任何输出,也没有错误。请在这件事上给予我帮助
with open("File1.csv", "rb") as in_file1, open("File2.csv", "rb") as in_file2,open("File3.csv", "wb") as out_file:
reader1 = csv.reader(in_file1)
reader2 = csv.reader(in_file2)
writer = csv.writer(out_file)
for row2 in reader2:
for row1 in reader1:
if row2[0] == row1[0]:
row2[1] = row1[1]
writer.writerow(row2)
以下是数据的样子:
File 1
A 100
B 200
C 300
D 400
E 500
FIle 2
A
C
E
E
E
D
File 3 (Should be)
A 100
C 300
E 500
E 500
E 500
D 400