Pandas: Can you access rolling window items
<p>Can you access pandas rolling window object. </p>

<pre><code>rs = pd.Series(range(10))
rs.rolling(window = 3)

#print's 
Rolling [window=3,center=False,axis=0]
</code></pre>

<p>Can I get as groups?: </p>

<pre><code>[0,1,2]
[1,2,3]
[2,3,4]
</code></pre>

<p>Here's a workaround, but waiting to see if anyone has pandas solution:</p>

<pre><code>def rolling_window(a, step):
    shape   = a.shape[:-1] + (a.shape[-1] - step + 1, step)
    strides = a.strides + (a.strides[-1],)
    return np.lib.stride_tricks.as_strided(a, shape=shape, strides=strides)

rolling_window(rs, 3)

array([[ 0,  1,  2],
       [ 1,  2,  3],
       [ 2,  3,  4],
       [ 3,  4,  5],
       [ 4,  5,  6],
       [ 5,  6,  7],
       [ 6,  7,  8],
       [ 7,  8,  9],
       [ 8,  9, 10]])
</code></pre>

python pandas