0

I am trying to find the difference between two csv file cell by cell. Following is the code I used however it uses sets and treats unable to locate difference if there are two rows with the same exact value.
For example:

First csv:

bob virgnia 22 
bob virgnia 22 
adam virginia 21
jack california 22

Second csv:

bob virgnia 22
adam virgnia 21
jack california 22

It is outputting with no difference.

# Read in the original and new file          
orig = open('T1.csv','r')
new = open('T2.csv','r')
#in new but not in orig
bigb = set(new) - set(orig)
# small = set(orig) - set(new)

# To see results in console if desired
print(bigb)
print()
# Write to output file    
with open('different.csv', 'w') as file_out:
    for line in bigb:
        file_out.write(line)

#close the files  
orig.close()    
new.close()    
file_out.close()
martineau
  • 119,623
  • 25
  • 170
  • 301
gannu
  • 105
  • 1
  • 9
  • https://stackoverflow.com/questions/7757626/compare-two-different-files-line-by-line-and-write-the-difference-in-third-file I think this answer will solve your problem. – harleenkaurx Apr 04 '20 at 16:54
  • What should the output be? Please [edit] your question and show what the expected difference between the two csv files to be. – martineau Apr 04 '20 at 17:20
  • output suppose to be bob virgnia 22 – gannu Apr 04 '20 at 20:30

0 Answers0