title: How to compare two csv files in Python
body: <p>I have two csv files. One is called 'Standard reg.csv', the other is 'Driver Details.csv'</p>
  
  <p>In 'Standard reg.csv' the first two lines are:</p>
  
  <pre><code>['Day', 'Month', 'Year', 'Reg Plate', 'Hour', 'Minute', 'Second', 'Speed over limit']
  ['1', '1', '2016', 'NU16REG', '1', '1', '1', '5816.1667859699355']
  </code></pre>
  
  <p>The first two lines in Driver Details.csv are:</p>
  
  <pre><code>['FirstName', 'LastName', 'StreetAddress', 'City', 'Region', 'Country', 'PostCode', 'Registration']
  ['Violet', 'Kirby', '585-4073 Convallis Street', 'Balfour', 'Orkney', 'United Kingdom', 'OC1X 6QE', 'NU16REG']
  </code></pre>
  
  <p>My code is this:</p>
  
  <pre><code>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')
  </code></pre>
  
  <p>It's a work-in-progress, but I can't seem to get the code to compare more than just the last line.</p>
  
  <p>With <code>print(reg)</code> after this line: <code>reg2 = row[7]</code></p>
  
  <p>it shows it has read that whole column.  The entire column is also printed when I do <code>print(reg2)</code> after:<code>reg2 = row[7]</code></p>
  
  <p>But at <code>if reg  == reg2:</code>
  it only reads the last lines of both columns and compares them and I'm not sure how to fix this. </p>
  
  <p>Thank you in advance.</p>