title: How to subset pandas time series by time of day
body: <p>I am trying to subset a pandas time series that spans multiple days by time of day. E.g., I only want times between 12:00 and 13:00.</p>
  
  <p>I know how to do this for a specific date, e.g.,</p>
  
  <pre><code>In [44]: type(test)
  Out[44]: pandas.core.frame.DataFrame
  
  In [23]: test
  Out[23]:
                             col1
  timestamp
  2012-01-14 11:59:56+00:00     3
  2012-01-14 11:59:57+00:00     3
  2012-01-14 11:59:58+00:00     3
  2012-01-14 11:59:59+00:00     3
  2012-01-14 12:00:00+00:00     3
  2012-01-14 12:00:01+00:00     3
  2012-01-14 12:00:02+00:00     3
  
  In [30]: test['2012-01-14 12:00:00' : '2012-01-14 13:00']
  Out[30]:
                             col1
  timestamp 
  2012-01-14 12:00:00+00:00     3
  2012-01-14 12:00:01+00:00     3
  2012-01-14 12:00:02+00:00     3
  </code></pre>
  
  <p>But I have failed to do it for any date using <code>test.index.hour</code> or <code>test.index.indexer_between_time()</code> which were both suggested as answers to similar questions. I tried the following:</p>
  
  <pre><code>In [44]: type(test)
  Out[44]: pandas.core.frame.DataFrame
  
  In [34]: test[(test.index.hour &gt;= 12) &amp; (test.index.hour &lt; 13)]
  Out[34]:
  Empty DataFrame
  Columns: [col1]
  Index: []
  
  In [36]: import datetime as dt
  In [37]: test.index.indexer_between_time(dt.time(12),dt.time(13))
  Out[37]: array([], dtype=int64)
  </code></pre>
  
  <p>For the first approach, I have no idea what <code>test.index.hour</code> or <code>test.index.minute</code> are actually returning:</p>
  
  <pre><code>In [41]: test.index
  Out[41]:
  &lt;class 'pandas.tseries.index.DatetimeIndex'&gt;
  [2012-01-14 11:59:56, ..., 2012-01-14 12:00:02]
  Length: 7, Freq: None, Timezone: tzlocal()
  
  In [42]: test.index.hour
  Out[42]: array([11, 23,  0,  0,  0,  0,  0], dtype=int32)
  
  In [43]: test.index.minute
  Out[43]: array([59, 50,  0,  0, 50, 50,  0], dtype=int32)
  </code></pre>
  
  <p>What are they returning? How can I do the desired subsetting? Ideally, how can I get both the two approaches above to work?</p>
  
  <p>Edit: The problem turned out to be the the index was invalid, which is evidenced by <code>Timezone: tzlocal()</code> above, as <code>tzlocal()</code> should not be allowed as timezone. When I changed my method of generating the index to <code>pd.to_datetime()</code>, according to the final part of the accepted answer, everything worked as expected.</p>