May-18-2018, 07:18 AM
(This post was last modified: May-18-2018, 07:51 AM by Prince_Bhatia.)
hi,
I am trying to create a program that will compare two csv files and display the results in new csv file.
In csv files cells have text value and integer value as well. I want if the change occurs and the cell value is TEXT it should append True against that value in new csv file and if the change occurs and the cell value is Integer it should append this text "Result is positive: change in value" and "Result is negative: change in value"
Below are my codes:
I am also attaching the samples files for your convience. Please Guide
I am trying to create a program that will compare two csv files and display the results in new csv file.
In csv files cells have text value and integer value as well. I want if the change occurs and the cell value is TEXT it should append True against that value in new csv file and if the change occurs and the cell value is Integer it should append this text "Result is positive: change in value" and "Result is negative: change in value"
Below are my codes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import csv with open ( 'book1.csv' , 'r' ) as t1: old_csv = t1.readlines() with open ( 'book2.csv' , 'r' ) as t2: new_csv = t2.readlines() with open ( 'update.csv' , 'w' ) as out_file: line_in_new = 0 line_in_old = 0 while line_in_new < len (new_csv) and line_in_old < len (old_csv): if old_csv[line_in_old] ! = new_csv[line_in_new]: out_file.write(new_csv[line_in_new]) else : line_in_old + = 1 line_in_new + = 1 |