Pandas DataFrame How to query the closest datetime index? : <p>How do i query for the closest index from a Pandas DataFrame? The index is DatetimeIndex</p>

<pre><code>2016-11-13 20:00:10.617989120   7.0 132.0
2016-11-13 22:00:00.022737152   1.0 128.0
2016-11-13 22:00:28.417561344   1.0 132.0
</code></pre>

<p>I tried this:</p>

<pre><code>df.index.get_loc(df.index[0], method='nearest')
</code></pre>

<p>but it give me <code>InvalidIndexError: Reindexing only valid with uniquely valued Index objects</code></p>

<p>Same error if I tried this:</p>

<pre><code>dt =datetime.datetime.strptime("2016-11-13 22:01:25", "%Y-%m-%d %H:%M:%S")
df.index.get_loc(dt, method='nearest')
</code></pre>

<p>But if I remove <code>method='nearest'</code> it works, but that is not I want, I want to find the closest index from my query datetime</p>
