title: python CSV intelligent parser and column matching
body: <p>I've couple of thousands of CSV files where most of them have following columns</p>
  
  <pre><code>threadSubject
  bccList
  sender_name
  recipient_names
  sender  
  dateReceived
  date    
  recipients
  subject 
  </code></pre>
  
  <p>Unfortunately depending on the CSV file each column if it is present might be at different columnt number therefore complicating parsing.</p>
  
  <p>What I need to do is extract from the input CSV files only these selected columns and put them all into single output file.</p>
  
  <p>I'm new to python and am sure there's perfectly easy way to achieve this but I can't figure it out.
  I'm not sure if should use Pandas or other mechanism.</p>
  
  <p>In logical code it should work more or less like this.</p>
  
  <pre><code>for file in (all files in current folder); do
    open file;
    get header and find out at which positions are interesting columns 
    #or match by column name;
  
    dump interesting columns into output file in the right order;
    close file;
  done
  </code></pre>
  
  <p>The tricky part of me is <code>get header...</code></p>
  
  <p>Would any of you have any advise how to do it in smart pythonic way?</p>
  
  <p>I thought about bash and parse it manually, but thought it might be a good idea to learn how to do it in python with your help.</p>
  
  <p>p.s. background of it is that I need to go through all emails for last 5 years and find out at what time was sent out first email and last email during each day. The CSVs I've were created based on Thunderbird MSF files using Mork tool. Once I'll have this CSV parsing done, I'll need to find out easy way to get time of first email and last email on the same day. BUt this is another story.</p>
  
  <p>Thanks in advance for all advises.</p>