substract from date tuple
<p>I have an index consisting of Date tuples.</p>

<pre><code>2005-02-04 00:00:00        31.81        31.81        31.81        31.81   
2005-02-07 00:00:00       31.885       31.885       31.885       31.885   
2005-02-08 00:00:00      31.5326      31.5326      31.5326      31.5326   
</code></pre>

<p>I would like to add a row at the top of the index, and I use the
following way:</p>

<pre><code>df.ix[ (df.index.min()) - dt.timedelta(minutes=5), :]    =
     ([ dict[n] for n in df.columns.values.tolist()])
</code></pre>

<p>dict contains some values, but it's irrelevant here I think. However,
I get the following error:</p>

<pre><code>TypeError: unsupported operand type(s) for -: 'tuple' and 'datetime.timedelta'
</code></pre>

<p>The type of the Index is: df.index.dtype gives type Object as opposed
to Datetime as it should I suppose. thanks</p>

<p>Actually I ve found it, you simply need to take the first element off the tuple, and it returns a 'TimeStamp' object: </p>

<pre><code>df.index.min()[0] - dt.timedelta(minutes=5) 
</code></pre>

<p>works </p>

python datetime pandas dataframe