title: comparing time in an if clause
body: <p>I am dealing with a large financial datasset (> 15gb) and trying to get (write to a CSV file) the quotes 30 mins before and after an announcement time. specifically, I will have 2 CSV files, 1 containing quotes data and 1 containing earning announcement timestamps. I have tried my codes as below: </p>
  
  <pre><code>import datetime
  import csv
  
  df1 = csv.DictReader(open('earning_announcements.csv'))
  df2 = csv.DictReader(open('quote_data.csv'))
  
  data_writer = csv.DictWriter(open('quotes_selected.csv', 'wb'), fieldnames=['RIC', 'Date[L]', 'Time[L]','Close Bid', 'No. Bids','Close Ask', 'No. Asks'])
  data_writer.writeheader()
  
  for row2 in df2:
      for row1 in df1:
          if (row2['RIC'][:3] == row1['RIC'] and 
              row2['Time'] &lt; row1['Time'] and 
              (row2['Time'] &gt;= (row1['Time']- datetime.timedelta(minutes=30)))):
              data_writer.writerow(row2)
  </code></pre>
  
  <p>my earning_announcement.csv(df1) looks like this (other columns have been neglected):</p>
  
  <pre><code>RIC Date        Time
  ACR 23-08-12    16:26:00
  ACR 23-08-12    16:22:00
  AEJ 25-02-11    15:34:00
  AEJ 31-08-11    15:39:00
  AEJ 29-02-12    16:10:00
  AEJ 31-08-12    16:08:00
  AFI 25-07-11    10:43:00
  </code></pre>
  
  <p>and the quote_data.csv (df2) looks like this:</p>
  
  <pre><code>RIC Date        Time    Close Bid   No. Bids    Close Ask   No. Asks
  ACR 20120823    15:52:00    3.89    0            3.9         0
  ACR 20120823    15:52:05    3.89    0            3.9         0
  ACR 20120823    15:52:10    3.89    1            3.9         0
  ACR 20120823    15:52:15    3.89    0            3.9         0
  ACR 20120823    15:52:20    3.89    0            3.9         1
  ACR 20120823    15:52:25    3.89    0            3.9         1
  ACR 20120823    15:52:30    3.89    5            3.9         0
  ACR 20120823    15:52:35    3.89    0            3.9         0
  ACR 20120823    15:52:40    3.88    17           3.89        6
  ACR 20120823    15:52:45    3.88    3            3.89        7
  </code></pre>
  
  <p>note: RIC is stock code
  I also want to classify whether it is before or after the announcement timestamps (i.e. create a column that say before/after) but dont know how.
  Can you guys please help me. I really appreciate it and sorry if my codes are too confusing.
  Thank you so much.</p>