Python: How to develop a between_time similar method when on pandas 0.9.0?
<p>I am stick to pandas 0.9.0 as I'm working under python 2.5, hence I have no <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.between_time.html" rel="nofollow">between_time</a> method available. </p>

<p>I have a DataFrame of dates and would like to filter all the dates that are between certain hours, e.g. between <code>08:00</code> and <code>09:00</code> for all the dates within the DataFrame <code>df</code>.</p>

<pre><code>import pandas as pd
import numpy as np
import datetime

dates = pd.date_range(start="08/01/2009",end="08/01/2012",freq="10min")
df = pd.DataFrame(np.random.rand(len(dates), 1)*1500, index=dates, columns=['Power'])
</code></pre>

<p>How can I develop a method that provides same functionality as <code>between_time</code> method?</p>

<p>N.B.: The original problem I am trying to accomplish is under <a href="http://stackoverflow.com/questions/40117702/python-filter-dataframe-in-pandas-by-hour-day-and-month-grouped-by-year">Python: Filter DataFrame in Pandas by hour, day and month grouped by year</a></p>

<p><strong>UPDATE:</strong></p>

<p>try to use:</p>

<pre><code>df.ix[df.index.indexer_between_time('08:00','09:50')]
</code></pre>

<p><strong>OLD answer:</strong></p>

<p>I'm not sure that it'll work on Pandas 0.9.0, but it's worth to try it:</p>

<pre><code>df[(df.index.hour &gt;= 8) &amp; (df.index.hour &lt;= 9)]
</code></pre>

<p>PS please be aware - it's not the same as <code>between_time</code> as it checks only hours and <code>between_time</code> is able to check <strong>time</strong> like <code>df.between_time('08:01:15','09:13:28')</code></p>

<p><strong>Hint</strong>: download a source code for a newer version of Pandas and take a look at the definition of <code>indexer_between_time()</code> function in   <code>pandas/tseries/index.py</code> - you can clone it for your needs</p>

python pandas python-2.5