title: Pandas - Computing the mean vector of a window when the start is column specific
body: <p>Consider the following data:</p>
  
  <pre><code>In [79]:
  
  df = pd.DataFrame( data=nr.randn(8,4), index=pd.date_range( '2014-01-01', periods=8 ), columns=string.split( 'z a o p' ) )
  df
  Out[79]:
  z   a   o   p
  2014-01-01   0.737081    0.409902    0.077970    1.710260
  2014-01-02  -0.686835   -1.588592    0.652161   -1.196529
  2014-01-03  -1.217688   -1.156016    1.448976    0.415068
  2014-01-04   0.336256   -0.559507    0.917721    0.106411
  2014-01-05   0.043473   -1.221673   -0.598708    1.489676
  2014-01-06  -0.858759    0.508017   -1.611998    0.581115
  2014-01-07  -0.672269   -0.247206   -0.312354    0.493086
  2014-01-08   1.346462   -1.805292    2.807642    0.365685
  8 rows × 4 columns
  </code></pre>
  
  <p>And for each column, I have a start date:</p>
  
  <pre><code>In [83]:
  start = pd.Series( data=pd.to_datetime( [ '2014-01-05', '2014-01-06', '2014-01-06', '2014-01-03' ] ), index=string.split( 'z a o p' ) )
  start
  Out[83]:
  z   2014-01-05
  a   2014-01-06
  o   2014-01-06
  p   2014-01-03
  dtype: datetime64[ns]
  In [94]:
  </code></pre>
  
  <p>The desired output is the mean vector of the 4 red vectors, where each red vector is centered around the corresponding start date:</p>
  
  <p><img src="https://i.stack.imgur.com/SxWhX.png" alt="Desired output"> </p>
  
  <p>My current solution is very straightforward. I just loop, add and divide:</p>
  
  <pre><code>res = pd.Series( data=[0.] * 3 )
  for name, dt in start.iteritems() :
      res += df.loc[ dt - datetime.timedelta( days=1 ): dt + datetime.timedelta( days=1 ), name ].values
  res /= 4
  res
  Out[94]:
  0   -0.670163
  1   -0.161360
  2   -0.327977
  dtype: float64
  </code></pre>
  
  <p>I am wondering if there is a slicker solution using pandas built-in functions.</p>