title: Looking for an efficient way to reorganize a pandas Dataframe
body: <p>I have data in a Dataframe structured like so...</p>
  <pre><code>       D           K         Factor        p
  0   -0.483128   -1.240024  -1.214765   -1.002418
  1   -0.692334   -1.632132   1.562630    0.997304
  2   -1.189383   -1.632132   1.562630    0.997304
  3   -1.691841   -1.632132   1.562630    0.997304
  4   -2.084926   -1.632132   1.562630    0.997304
  </code></pre>
  <p>I'm trying to reorganize the data into a new structure where each row contains 'period' number of rows from the existing data.  Moves ahead one row in existing and the stacks the next 'period lines'.</p>
  <p>the function so far:</p>
  <pre><code>def prepData(seq, period):
      newStacks = pd.DataFrame()
      for pos in range(0, len(seq) - (period+1), 1):
          chunk = (seq[pos:pos + period])
          stack = []
          for sliver in range(0, len(chunk), 1):
              piece = (chunk.iloc[sliver:])
              print(piece)
              stack.append(piece) 
          
          newStacks.append(chunk)
  
  return newStacks
  </code></pre>
  <p>this obviously is not efficient and aside doesn't produce the desire structure.  The aim is to get a structure like below considering period = 3</p>
  <pre><code>0   -0.483128   -1.240024   -1.214765   -1.002418   -0.692334   -1.632132   1.562630    0.997304 -1.189383  -1.632132   1.562630    0.997304
  1   -0.692334   -1.632132   1.562630    0.997304    -1.189383   -1.632132   1.562630    0.997304 -1.691841  -1.632132   1.562630    0.997304
  2   -1.189383   -1.632132   1.562630    0.997304    -1.691841   -1.632132   1.562630    0.997304 -2.084926  -1.632132   1.562630    0.997304
  </code></pre>
  <p>AA Simple way to accomplish this  would be appreciated.</p>