Similar to the the question here, I need to compare two CSV files and print out the changes. The only difference to this question if I have a number inputs with this name I want to write them all to the Differences.csv file. I'm using the same code as the link above:
with open('old_file.csv','rb') as file1:
existingLines = [line for line in csv.reader(file1, delimiter=',')]
with open('new_file.csv','rb') as file2:
reader2 = csv.reader(file2,delimiter=',')
with open('Differences.csv', 'wb') as h:
writer = csv.writer(h)
for row in reader2:
if row not in new and row not in existingLines:
new.append(row)
I've an example below of the output I want below:
old_file = new_file =
Fruit Length Width Fruit Length Width
Grape 0.3 0.4 Grape 0.3 0.4
Grape 0.2 0.5 Grape 0.2 0.5
Apple 0.8 1.0 Apple 0.8 1.0
Apple 1.0 1.1 Apple 1.0 1.0
Plum 1.3 1.4
Plum 1.1 1.2
Differences =
Fruit Length Width
Apple 0.8 1.0
Apple 1.0 1.0
Plum 1.3 1.4
Plum 1.1 1.2
So as the apples width has changed I want to print both apples again. Many thanks