I have two CSV files, both are different but similar. I would like to compare them and output changes and if a variable has been added or removed. I would like to output the changes in either a new CSV or text file.
Below is some code of what I have already tried as well as the two csv files. I would also be willing to use difflib and output that to a text file.
file1.csv:
name1,2.0001
name2,3.4010
name4,4.0000
name5,1.0000
name6,1.0000
name8,1.9001
name10,2.7654
file2.csv:
name1,3.0000
name2,3.4010
name3,1.0000
name5,1.0901
name6,1.0000
name7,3.4445
name11,8.0009
name12,0.1180
Here is code I have tried:
with open('file1.csv', 'r') as file1, open('file2.csv', 'r') as file2:
file1 = file1.readlines()
file2 = file2.readlines()
with open('new_file.csv', 'w') as outFile:
for line in file2:
if line not in file1:
outFile.write(line)
Expected output would be either a csv file or text file that would show things like:
name1 value changed from 2.0001 to 3.0000
name3 value added
name4 value removed
name5 value changed from 1.0000 to 1.0901
name7 value added
name8 value removed
name10 value removed
name11 value added
name12 value added