title: Python Pandas rolling aggregate a column of lists
body: <p>I have a simple dataframe df with a column of lists <code>lists</code>. I would like to generate an additional column based on <code>lists</code>.</p>
  
  <p>The <code>df</code> looks like:</p>
  
  <pre><code>import pandas as pd
  lists={1:[[1]],2:[[1,2,3]],3:[[2,9,7,9]],4:[[2,7,3,5]]}
  #create test dataframe
  df=pd.DataFrame.from_dict(lists,orient='index')
  df=df.rename(columns={0:'lists'})
  df
  
            lists
  1           [1]
  2     [1, 2, 3]
  3  [2, 9, 7, 9]
  4  [2, 7, 3, 5]
  </code></pre>
  
  <p>I would like <code>df</code> to look like this:</p>
  
  <pre><code>df
  Out[9]: 
            lists                 rolllists
  1           [1]                       [1]
  2     [1, 2, 3]              [1, 1, 2, 3]
  3  [2, 9, 7, 9]     [1, 2, 3, 2, 9, 7, 9]
  4  [2, 7, 3, 5]  [2, 9, 7, 9, 2, 7, 3, 5]
  </code></pre>
  
  <p>Basically I want to 'sum'/<code>append</code> the rolling 2 lists.  Note that row 1, because I only have 1 list <a href="https://stackoverflow.com/questions/44501875/pandas-dataframe-column-of-lists-create-column-of-sets-of-cumulative-lists-an">1</a>, rolllists is that list.  But in row 2, I have 2 lists that I want appended.  Then for row three, append <code>df[2].lists</code> and <code>df[3].lists</code> etc.  I have worked on similar things before, reference this:<a href="https://stackoverflow.com/questions/44501875/pandas-dataframe-column-of-lists-create-column-of-sets-of-cumulative-lists-an">Pandas Dataframe, Column of lists, Create column of sets of cumulative lists, and record by record differences</a>.<br>
  In addition, if we can get this part above, then I want to do this in a <code>groupby</code> (so the example below would be 1 group for example, so for instance the <code>df</code> might look like this in the <code>groupby</code>):</p>
  
  <pre><code>  Group         lists                 rolllists
  1     A           [1]                       [1]
  2     A     [1, 2, 3]              [1, 1, 2, 3]
  3     A  [2, 9, 7, 9]     [1, 2, 3, 2, 9, 7, 9]
  4     A  [2, 7, 3, 5]  [2, 9, 7, 9, 2, 7, 3, 5]
  5     B           [1]                       [1]
  6     B     [1, 2, 3]              [1, 1, 2, 3]
  7     B  [2, 9, 7, 9]     [1, 2, 3, 2, 9, 7, 9]
  8     B  [2, 7, 3, 5]  [2, 9, 7, 9, 2, 7, 3, 5]
  </code></pre>
  
  <p>I have tried various things like df.lists.rolling(2).sum() and I get this error:</p>
  
  <pre><code>TypeError: cannot handle this type -&gt; object 
  </code></pre>
  
  <p>in Pandas 0.24.1 and unfortunatley in Pandas 0.22.0 the command doesn't error, but instead returns the exact same values as in <code>lists</code>.  So Looks like newer versions of Pandas can't sum lists? That's a secondary issue.</p>
  
  <p>Love any help!  Have Fun!</p>