I have two csv files generated from 2 different python scripts sample1.csv and sample2.csv.
sample1.csv has the following data:-
92 90 85
100 89 78
76 45 78
76 54 86
sample2.csv has the same data but also with headers:-
Maths Science English
92 90 85
100 89 78
76 45 78
76 54 86
My code works comparing the 2 csv files line by line. If there were no headers, then it would work perfectly. Assuming that there is no way to get rid of the header at the first place and will always be there, how can I skip that line so that my comparison would start from 1st line of the sample1.csv with 2nd line of sample2.csv and so on.
My code snippet:-
import csv
import sys
list1 = ["sample1.csv"]
list2 = ["sample2.csv"]
for i,j in zip(list1,list2):
f1_name = i
f2_name = j
f1 = open(f1_name,'r').readlines()
f2 = open(f2_name,'r').readlines()
count1 = 0
for line in f1:
result = line.strip("\n")
count1+=1
if line != "\n" and line in f2:
print "Line({0}) in {1} FOUND in Line{2} in {3}".format(
str(result),
f1_name,
str(1+f2.index(line)),
f2_name)
else:
if line != "\n":
print "Line({0}) in {1} NOT FOUND in {2}".format(
line.strip("\n"),
f1_name,
f2_name)
It displays the result in format:-
Line(92,90,85) in sample1.csv NOT FOUND in sample2.csv
and so on....