title: Merge Two CSV files in Python
body: <p>I have two csv files and I want to create a third csv from the a merge of the two. Here's how my files look:</p>
  
  <p><strong>Num  | status</strong><br>
  1213 | closed<br>
  4223 | open<br>
  2311 | open<br></p>
  
  <p>and another file has this:</p>
  
  <p><strong>Num  | code</strong><br>
  1002 | 9822<br>
  1213 | 1891<br>
  4223 | 0011<br></p>
  
  <p>So, here is my little code that I was trying to loop through but it does not print the output with the third column added matching the correct values.</p>
  
  <pre><code>def links():
      first = open('closed.csv')
      csv_file = csv.reader(first)
  
      second = open('links.csv')
      csv_file2 = csv.reader(second)
  
      for row in csv_file:  
          for secrow in csv_file2:                             
              if row[0] == secrow[0]:
                  print row[0]+"," +row[1]+","+ secrow[0]
                  time.sleep(1)
  </code></pre>
  
  <p>so what I want is something like:</p>
  
  <p><strong>Num | status | code</strong><br />
  1213 |  closed | 1891<br />
  4223 |  open    | 0011<br />
  2311 |  open    |   blank no match <br /></p>