identify non pandas datetimeindex?
<p>How to identify and delete non <code>datetimeindex</code> rows in following index.</p>

<p><code>Index([nan, nan, nan, nan, u'aveValue', u'minValue', u'maxValue', u'firstValue', u'lastValue', u'nPointsTot', u'nGood', u'nBlankTimes', u'nBlankValues', u'level_nGood', u'level_nSuspect', u'level_nBad', u'status_nGood',  u'2009-01-01 00:00:00', u'2009-01-01 00:05:00', u'2009-01-01 00:10:00', u'2009-01-01 00:15:00', u'2009-01-01 00:20:00', u'2009-01-01 00:25:00', u'2009-01-01 00:30:00', u'2009-01-01 00:35:00', u'2009-01-01 00:40:00', u'2009-01-01 00:45:00', u'2009-01-01 00:50:00', u'2009-01-01 00:55:00', u'2009-01-01 01:00:00', u'2009-01-01 01:05:00', u'2009-01-01 01:10:00', u'2009-01-01 01:15:00', , ...], dtype='object')</code></p>

<p>I need to remove the rows where index is not a timestamp.
What's the most efficient way to do this?</p>

<pre><code>#type (df[0].index)
=&gt; class 'pandas.core.index.Index'
</code></pre>

<p>Convert the index <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow">to datetime</a>, coerce errors, and filter <code>NaT</code> results:</p>

<pre><code>df[pd.to_datetime(df.index, errors='coerce').to_series().notnull().values]
</code></pre>

<p>In order to use the <code>notnull</code> method, I convert the datetime index to a series. I then convert the series to a boolean vector that can be used for indexing.</p>

<p><strong>Edit</strong></p>

<p>This should work for any pandas version:</p>

<pre><code>df[pd.Series(pd.to_datetime(df.index, errors='coerce')).notnull().values]
</code></pre>

python pandas