title: Using the pandas Rolling object to create a sliding window of lists
body: <p><a href="https://stackoverflow.com/questions/39674713/neural-network-lstm-input-shape-from-dataframe/40005797#40005797">This outstanding post</a> illustrates quite clearly how to use the pandas <code>cumsum()</code> DataFrame method to build a 3D tensor containing a column with lists of lists whose dimensions make them suitable to be used as time series input to an LSTM. I would like to do something very similar but with a rolling list of lists instead of a cumulative aggregation of lists.</p>
  
  <p>For example. Say you had a DataFrame with 3 time series thus:</p>
  
  <pre><code> A   B   C
   1   2   3
   4   5   6
   7   8   9
  10  11  12
  </code></pre>
  
  <p>The article I linked to above, shows you how to use pandas <code>cumsum()</code> to build a DataFrame column of nested lists that look like this:</p>
  
  <pre><code>[[1, 2, 3]]
  [[1, 2, 3], [4, 5, 6]]
  [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  </code></pre>
  
  <p>The key lines of python code that accomplish this are as follows:</p>
  
  <pre><code>input_cols =  list(df.columns)
  df['single_list'] = df[input_cols].apply(
                         tuple, axis=1).apply(list)
  df['double_encapsulated'] = df.single_list.apply(
                                        lambda x: [list(x)])
  </code></pre>
  
  <p>But I want a <em>rolling window</em> of lists, not a cumulative sum of lists. It should look like this:</p>
  
  <pre><code>[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
  [[4, 5, 6], [7, 8, 9], [10, 11, 12]]
  [[7, 8, 9], [10, 11, 12], [13, 14, 15]]
  </code></pre>
  
  <p>Can this be done with a Rolling object? </p>