title: How to slice Pandas data frame by column header value when the column header is a date-time value?
body: <p>I have an excel file where the column name consists of date-time value.</p>
  
  <p><a href="https://i.stack.imgur.com/w1BoO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w1BoO.png" alt=""></a></p>
  
  <p>As you can see the header value is in date-time format. I have loaded this to Pandas dataframe and the header values are indeed saved as date-time value.</p>
  
  <p>Now if I need to query from Pandas such as, "pick all columns which are greater than May-15" how can I do that?</p>
  
  <p>I am aware that by querying <code>df[df.columns[3:]]</code> I can achieve this. But I really want to slice based on the value of <strong>column header</strong> and not based on the <strong>position</strong> of the column.</p>
  
  <p>Please help.</p>
  
  <hr>
  
  <p><strong>Edit</strong>: 
  Based on the answers below, I figured out a way to query the column values. Adding it here for future reference.</p>
  
  <pre><code>from datetime import datetime
  
  df[[col for col in df.columns if col not in ("Name", "Location") 
             and col &gt;= datetime(2015,4,1) 
             and col &lt;= datetime(2016,3,1)]]
  </code></pre>
  
  <p>or </p>
  
  <pre><code>from datetime import datetime
  
  df.loc[:, [col for col in df.columns if col not in ("Name", "Location") 
         and col &gt;= datetime(2015,4,1) 
         and col &lt;= datetime(2016,3,1)]]
  </code></pre>
  
  <p>The 1st solution is the most elegant.
  Conceptually, to column slicing in Pandas works when the intended columns are provided as a list. List comprehenion is used to slice the columns based on column label values. (not the values within the column). In the examples, I have filtered out "Name" and "Location" columns since I am comparing the remaining columns based on datatime value.</p>