title: How to speed up apply method with lambda in pandas with datetime
body: <p>I'm new to pandas.</p>
  
  <p>I have a very simple dataframe named <code>dlf</code> with an index and two columns with 40k-row. It is loaded as so:</p>
  
  <pre><code>d = pd.DataFrame.from_csv(csvsLocation + 'name.csv', index_col='ID', infer_datetime_format=True)
  d['LAST'] = pd.to_datetime(d['LAST'], format = '%d-%b-%y')
  d['FIRST'] = pd.to_datetime(d['FIRST'], format = '%d-%b-%y')
  dlf = d[['LAST', 'FIRST']]
  </code></pre>
  
  <p>It looks something like this:</p>
  
  <pre><code>    LAST    FIRST
  ID      
  1   1997-04-17  1991-10-04
  3   2009-02-13  1988-07-07
  5   2009-10-24  1995-12-06
  6   1996-04-31  1989-03-14
  </code></pre>
  
  <p><strong>Running this apply method takes 5 seconds</strong>:</p>
  
  <pre><code>year = 1997
  dlf[str(year)] = dlf.apply(lambda row: 1*(year &gt;= row['FIRST'].year and year &lt;= row['LAST'].year), axis=1)
  </code></pre>
  
  <p>I need this sped up because I intend to run it hundreds of times.</p>
  
  <p>I suspect the issue is in using lambda.</p>
  
  <p>What have I done wrong, and/or how can I speed it up?</p>