I am trying to compare values of a particular column between 2 csv. I tried the following code for the same. However, I am not getting any output and no error too. Please help me with this
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)
Here is how the data looks like:
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