I have two .csv
files with a single row but with many columns. I wish to compare the data in the columns (except the first 3 columns) and output a new .csv
containing the subtraction of the files, computed as baseline - test
.
test1.csv
20170223, 433000000, 8k, -50, -50, -10, -50, -50
baseline.csv
20170223, 433000000, 8k, -50, -50, -50, -50, -50
The resultant .csv
file should read something like:
20170223, 433000000, 8k, 0, 0, -40, -0, -0
I am able to bring up the .csv
files but it is the column position and calculation that is proving difficult.
This is what i have so far:
import csv
with open('test001.csv', 'r') as f:
reader = csv.reader(f, delimiter = ',')
first_list = list(reader)
f.close()
with open('test002.csv', 'r') as f:
reader = csv.reader(f)
second_list = list(reader)
f.close()
result_list = list()
list_a = list()
list_b = list()
for row in first_list:
for x in range(0, 6):
result_list.append(row[x])
for x in range(6, len(row)-1):
list_a.append(row[x])
for row in second_list:
for x in range(6, len(row)-1):
print(row[x])
list_b.append(row[x])
for x in range(0, len(list_a)-1):
a = float(list_a[x])
b = float(list_b[x])
c = a-b
result_list.append(c)
myfile = open('difference.csv', 'w')
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
wr.writerow(result_list)
myfile.close()