I'm trying to obtain the difference between two csv files A.csv and B.csv in order to obtain new rows added in the second file. A.csv has the following data.
acct ABC 88888888 99999999 ABC-GHD 4/1/18 4 1 2018 Redundant/RSK
B.csv has the following data.
acct ABC 88888888 99999999 ABC-GHD 4/1/18 4 1 2018 Redundant/RSK
acct ABC 88888888 99999999 ABC-GHD 4/1/18 4 1 2018 DT/89
To write the new rows added into an output file I'm using the following script.
input_file1 = "A.csv"
input_file2 = "B.csv"
output_path = "out.csv"with open(input_file1, 'r') as t1:fileone = set(t1)
with open(input_file2, 'r') as t2, open(output_path, 'w') as outFile:for line in t2:if line not in fileone:outFile.write(line)
Expected output is :
acct ABC 88888888 99999999 ABC-GHD 4/1/18 4 1 2018 DT/89
Output obtained through the above script is :
acct ABC 88888888 99999999 ABC-GHD 4/1/18 4 1 2018 Redundant/RSK
acct ABC 88888888 99999999 ABC-GHD 4/1/18 4 1 2018 DT/89
I'm not sure where I'm making a mistake, tried debugging it but with no progress.