Python pandas resampling instantaneous hourly data to daily timestep including 00:00 of next day
<p>Let's say I have a series of instantaneous temperature measurements (i.e. they capture the temperature at an exact moment in time).</p>

<pre><code>index = pd.date_range('1/1/2000', periods=9, freq='T')
series = pd.Series(range(9), index=index)

series
Out[130]: 
2000-01-01 00:00:00    0
2000-01-01 06:00:00    1
2000-01-01 12:00:00    2
2000-01-01 18:00:00    3
2000-01-02 00:00:00    4
2000-01-02 06:00:00    5
2000-01-02 12:00:00    6
2000-01-02 18:00:00    7
2000-01-03 00:00:00    8
Freq: 6H, dtype: int64
</code></pre>

<p>I want to get a average of daily temperature.  The problem is that I want to include 00:00:00 from the current day and the next day in the average for the current day.  For example I want to average 2000-01-01 00:00:00 to 2000-01-02 00:00:00 inclusive.  The pandas resample function will not include 2000-01-02 in the bin because it's a different day.</p>

<p>I would imagine this situation comes up often when dealing with instantaneous measurements that need to be resampled.  What's the solution?</p>

<p><strong><em>setup</em></strong>  </p>

<pre><code>index = pd.date_range('1/1/2000', periods=9, freq='6H')
series = pd.Series(range(9), index=index)
series


2000-01-01 00:00:00    0
2000-01-01 06:00:00    1
2000-01-01 12:00:00    2
2000-01-01 18:00:00    3
2000-01-02 00:00:00    4
2000-01-02 06:00:00    5
2000-01-02 12:00:00    6
2000-01-02 18:00:00    7
2000-01-03 00:00:00    8
Freq: 6H, dtype: int64
</code></pre>

<p><strong><em>solution</em></strong>  </p>

<pre><code>series.rolling(5).mean().resample('D').first()

2000-01-01    NaN
2000-01-02    2.0
2000-01-03    6.0
Freq: D, dtype: float64
</code></pre>

python pandas