Pandas: Select data between Sunday 23:00-Friday 23:00 (1 year span)
<p>I have the timeseries of Euro-US Dollar Exchange Rate at minute granularity spanning the entire 2015 year, including non-trading days (ex.weekends) where the timeseries value get repeated for the entire non-trading period.</p>

<p>I need to discard such periods by selecting only the data between Sunday 23:00 pm and Friday 23:00 pm.</p>

<p>I haven't found a solution yet for Pandas (I know how to select between times inside a day and select between days). I could simply shift the time by 1h and then select only the business days but this is a sub-optimal solution.</p>

<p>Any idea on how to achieve this?</p>

<p>Example of data:</p>

<pre><code>Local time,              Open,    High,    Low,     Close,   Volume
02.01.2015 22:58:00.000, 1.20008, 1.20016, 1.20006, 1.20009, 119.84
02.01.2015 22:59:00.000, 1.20009, 1.20018, 1.20004, 1.20017, 40.61
02.01.2015 23:00:00.000, 1.20017, 1.20017, 1.20017, 1.20017, 0
02.01.2015 23:01:00.000, 1.20017, 1.20017, 1.20017, 1.20017, 0
...
04.01.2015 22:58:00.000, 1.20017, 1.20017, 1.20017, 1.20017, 0
04.01.2015 22:59:00.000, 1.20017, 1.20017, 1.20017, 1.20017, 0
04.01.2015 23:00:00.000, 1.19495, 1.19506, 1.19358, 1.19410, 109.4
04.01.2015 23:01:00.000, 1.19408, 1.19414, 1.19052, 1.19123, 108.12
...
</code></pre>

<p>consider the <code>pd.DataFrame</code> <code>df</code> and <code>pd.tseries.index.DatetimeIndex</code> <code>tidx</code></p>

<pre><code>tidx = pd.date_range('2010-01-01', '2011-01-01', freq='H')
df = pd.DataFrame(np.ones((tidx.shape[0], 2)), tidx, columns=list('AB'))
</code></pre>

<p>we can construct a series of values for which to filter</p>

<pre><code>day_hour = (((tidx.weekday + 1) % 7) * 100) + tidx.hour
</code></pre>

<p>determine which values are prior to Friday 23:00</p>

<pre><code>before_friday = day_hour &lt;= 523
</code></pre>

<p>And after Sunday 23:00</p>

<pre><code>after_sunday = day_hour &gt;= 23
</code></pre>

<p>Filter our <code>df</code> based on above conditions</p>

<pre><code>df[before_friday &amp; after_sunday]
</code></pre>

python datetime pandas time-series datetimeindex