I am having difficulty comparing two CSV files and printing out a separate report. I want my script to first match the IDs on the two files then compare the rest of row and print out a separate report showing the difference. The script I have compares two files and prints difference but won't work if the new file has additional rows.
example of the two files:
OLD file
ID fname lname status
1 joe pol active
2 peters dol active
3 john nol active
4 mike sol active
New file
ID fname lname status
1 joe pol active
2 peter dol active
67 ryan olson stop
3 johnny nolly stop
4 mike sol active
Code:
import csv
orig = open('OLD.csv','r')
new = open('NEW.csv','r')
Change = set(new) - set(orig)
print(Change)
with open('OLD.csv', mode='r') as infile:
reader = csv.reader(infile)
with open('different.csv', 'w') as file_out:
for line in Change:
file_out.write(line)
orig.close()
new.close()
file_out.close()