I have two csv files. One is called 'Standard reg.csv', the other is 'Driver Details.csv'
In 'Standard reg.csv' the first two lines are:
['Day', 'Month', 'Year', 'Reg Plate', 'Hour', 'Minute', 'Second', 'Speed over limit']
['1', '1', '2016', 'NU16REG', '1', '1', '1', '5816.1667859699355']
The first two lines in Driver Details.csv are:
['FirstName', 'LastName', 'StreetAddress', 'City', 'Region', 'Country', 'PostCode', 'Registration']
['Violet', 'Kirby', '585-4073 Convallis Street', 'Balfour', 'Orkney', 'United Kingdom', 'OC1X 6QE', 'NU16REG']
My code is this:
import csv
file_1 = csv.reader(open('Standard Reg.csv', 'r'), delimiter=',')
file_2 = csv.reader(open('Driver Details.csv', 'r'), delimiter=',')
for row in file_1:
reg = row[3]
avgspeed = row[7]
for row in file_2:
firstname = row[0]
lastname = row[1]
address = row[2]
city = row[3]
region = row[4]
reg2 = row[7]
if reg == reg2:
print('Match found')
else:
print('No match found')
It's a work-in-progress, but I can't seem to get the code to compare more than just the last line.
With print(reg)
after this line: reg2 = row[7]
it shows it has read that whole column. The entire column is also printed when I do print(reg2)
after:reg2 = row[7]
But at if reg == reg2:
it only reads the last lines of both columns and compares them and I'm not sure how to fix this.
Thank you in advance.