csv file comparison using python -


I tried this script to compare two CSV files:

  import Csv file1 = open ("1.ccv", "r") reader 1 = csv Reader (File 1) Reader 1. Xx () file2 = open ("2.ccv", "r") reader2 = csv Reader (file2) Reader 2.Entax () File3 = open ("file3.txt", "w") file4 = open ("file4.txt", "w") file1.seek (0, 0) file2.seek (0, 0) list1 = file1.readlines () List2 = file2.readlines () for I in list1: j to list2: if i == j: file3.write (i) file3.write (j) else : File4.write (i) file4.write (j) Continue   

and output that I'm getting with the header and repeating the mismatched files as well. For example, if my 1.csv contains

  name pay 20000 b 15000 c 10000   

2. CSV in

  Name 40000D 10000B15000C9000   

should be output

  file 3: b 15000 b 15000 file 4: 20000 a 40000 c 10000 c 9000 ------ (1.csv no d) d 10000    

Would not it be easier to compare dictionaries with keywords as keywords and values? There may be a way to populate dict :

  import csv csv.register_dialect ('spaces', delimiter = '') Pay 1 = {} open ( 'L1. CCV') L1: Reader 1 = CSV. Reader 1.next () # Skip header salary as reader (L1, Dielect = 'blank space') = 1 line {0]: line [1] for print in line [1] Print pay 1    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -