For half-hourly intervals can I use Pandas TimeDeltaIndex, PeriodIndex or DateTimeIndex?
<p>I have a table of data values that should be indexed with half-hourly intervals, and I've been processing them with Pandas and Numpy. Currently they're in CSV files and I import them using <code>read_csv</code> to a dataframe with only the interval-endpoint as an index. I am uncomfortable with that and want to have the intervals themselves as the index.</p>

<p>I do not know whether to use a <code>DateTimeIndex</code>, a <code>PeriodIndex</code> or a <code>TimedeltaIndex</code>... All of them seem very similar in practice, to me. My operations include </p>

<ul>
<li>Looking up a particular interval</li>
<li>Checking if a DateTime is contained in a particular interval</li>
<li>Intersection and (Set)Difference of intervals</li>
<li>Split and join intervals</li>
</ul>

<p>Can Pandas even do all of these? Is it advisable? I already am using <a href="https://pypi.python.org/pypi/interval/1.0.0" rel="nofollow">this interval library</a>, would using Pandas <code>tslib</code> and <code>period</code> be better?</p>

<p>if you only need a series with time interval of 30 minutes you can do this:</p>

<pre><code>import pandas as pd
import datetime as dt

today = dt.datetime.date()
yesterday = dt.datetime.date()-dt.timedelta(days=1)
time_range = pd.date_range(yesterday,today, freq='30T')
</code></pre>

<p>now you could use it to set an index such has</p>

<pre><code>pd.DataFrame(0, index=time_range,columns=['yourcol'])

Out[35]: 
                     yourcol
2016-09-25 00:00:00        0
2016-09-25 00:30:00        0
2016-09-25 01:00:00        0
2016-09-25 01:30:00        0
2016-09-25 02:00:00        0
</code></pre>

<p>this would be a DateTimeIndex</p>

<p>you can read more about time interval in pandas here: <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/timeseries.html#offset-aliases</a></p>

python datetime pandas intervals