Find the difference of the two csv files
Question: I have two csv files named `x.csv` and `y.csv`. `x.csv` has only one row -
`Column A:0, Column B:1, Column C:2, Column D:3`. In `y.csv`, only one row -
`Column A:2, Column B:3, Column C:4`. I need to find the difference of the two
csv files using python and output to a third csv file.

So far I have tried `with open('x.csv','rb') as f1, open('y.csv','rb') as f2`


Answer: From what I understand from the question, this should compare the files and
create a third csv with the differences for each cell. Personally I don't
think this is a very elegant solution and will break down in a range of
scenarios but it should at least get you started. This was partially based off
the linked Q/A given in the comments.

    
    
    import csv
    
    
    def csv_get(csvfile):
        with open(csvfile) as f:
            for row in csv.reader(f):
                for i in row:
                    yield i
    
    
    def csv_cmp(csvfile1, csvfile2, output):
        row = []
        read_file_2 = csv_get(csvfile2)
    
        for value_1 in csv_get(csvfile1):
            value_2 = read_file_2.next()
            print("File 1: {} File 2: {}").format(value_1, value_2)
            difference = int(value_1) - int(value_2)
            row.append(difference)
    
        with open(output, "w") as output_file:
            csv.writer(output_file).writerow(row)
    
        read_file_2.close()
    
    csv_cmp(csvfile1="C:\\...\\a.csv",
            csvfile2="C:\\...\\b.csv",
            output="C:\\...\\c.csv")
    

