How can I advance the index of a pandas.dataframe by one quarter?
<p>I would like to shift the index of a pandas.dataframe by one quarter. The  dataframe looks like:</p>

<pre><code>            ID   Nowcast  Forecast
1991-01-01   35   4144.70   4137.40
1991-01-01   40   4114.00   4105.00
1991-01-01   60   4135.00   4130.00
....
</code></pre>

<p>So far, I calculate the number of occurrences of the first timestamp <code>1991-01-01</code> and shifted the dataframe accordingly. The code is: </p>

<pre><code>Stamps = df.index.unique()
zero = 0
for val in df.index:
    if val == Stamps[0]:
        zero = zero + 1
df = df.shift(zero)
</code></pre>

<p>The operation results in the following dataframe: </p>

<pre><code>              ID   Nowcast  Forecast 
1991-04-01   35.0   4144.70   4137.40       
1991-04-01   40.0   4114.00   4105.00       
1991-04-01   60.0   4135.00   4130.00  
</code></pre>

<p>The way I'm doing this strikes me as inefficient and error-prone. Is there a better way? </p>

<p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#dateoffset-objects" rel="nofollow">pd.DateOffset()</a>:</p>

<pre><code>In [110]: df
Out[110]:
            ID  Nowcast  Forecast
1991-01-01  35   4144.7    4137.4
1991-01-01  40   4114.0    4105.0
1991-01-01  60   4135.0    4130.0

In [111]: df.index += pd.DateOffset(months=3)

In [112]: df
Out[112]:
            ID  Nowcast  Forecast
1991-04-01  35   4144.7    4137.4
1991-04-01  40   4114.0    4105.0
1991-04-01  60   4135.0    4130.0
</code></pre>

python pandas