Python Pandas Custom DateTime Index
<p>I'm looking to reindex my data using a custom DateTime index.  I would like the index to be: Sun 5pm-Mon 4PM; Mon 5PM-Tues 4PM;Tues 5PM-Wed 4PM; Wed 5PM-Thurs 4pm; Thurs 5PM-Fri 4PM, in a 1 minute interval.  I have been playing around with the code below but I cant seem to get any data to populate in time_stamps. It seems like my issue might be with when the business day starts and ends and I am not sure how to get around that. Any help is appreciated.</p>

<pre><code>import pandas as pd
from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay
import datetime as dt


BDAY_US=CustomBusinessDay(calendar=USFederalHolidayCalendar())
sample_freq= '1min'
dates= pd.date_range(start='2016-07-11',end='2016-07-21', freq=BDAY_US ).date
times = pd.date_range(start='17:00:00', end='16:00:00', freq=sample_freq).time[1:]
time_stamps = [dt.datetime.combine(date, time) for date in dates for time in times]
</code></pre>

<p>Similar to my answer <a href="http://stackoverflow.com/a/36794030/5276797">here</a>, you could generate the full range of timestamps, then remove those you are not interested in:</p>

<pre><code>time_stamps = pd.date_range('2016-07-11', '2016-07-21', freq='1min')
mask = ~((time_stamps.hour &gt; 16) &amp; (time_stamps.hour &lt; 17))
time_stamps[mask]
</code></pre>

<p>There are two complications:</p>

<p><strong>First</strong>, you need to remove Fri 5pm - Sun 4pm</p>

<pre><code>weekend_mask = ~(
    ((time_stamps.dayofweek == 4) &amp; (time_stamps.hour &gt;= 17)) |
     (time_stamps.dayofweek == 5) |
    ((time_stamps.dayofweek == 6) &amp; (time_stamps.hour &lt;= 16))
)
mask = mask &amp; weekend_mask
</code></pre>

<p><strong>Second</strong>, you want to remove holidays. This part of my linked <a href="http://stackoverflow.com/a/36794030/5276797">answer</a> may help:</p>

<p>You can include a calendar by adding a condition to the mask:</p>

<pre><code>import numpy as np
np.in1d(index.date, calendar)
</code></pre>

<p>where calendar would be a numpy array of datetime objects.</p>

python datetime pandas