I have 2 CSVs which are New.csv and Old.csv that are have around 1K rows and 10 columns that has a structure like this:
If there is a longName (first column) in in the new.csv that is not in the old.csv, I would like that entire new.csv row to be appended to the changes.csv.
I started off by doing this but it does not work well at all:
def deltaFileMaker():
with open('Old.csv', 'r', encoding='utf-8') as t1, open('New.csv', 'r', encoding='utf-8') as t2:
fileone = t1.readlines()
filetwo = t2.readlines()
with open('changes.csv', 'w', encoding='utf-8') as outFile:
for line in filetwo:
if line not in fileone:
outFile.write(line)
deltaFileMaker()
I also tried to use csv-diff but I could not find a way to convert its output to a csv file
Update
def deltaFileMaker():
from csv_diff import load_csv, compare
diff = compare(
load_csv(open("old.csv",encoding="utf8"), key="longName"),
load_csv(open("new.csv",encoding="utf8"), key="longName")
)
with open('changes.csv', 'w',encoding="utf8") as f:
w = csv.DictWriter(f, diff.keys())
w.writeheader()
w.writerow(diff)
deltaFileMaker()

