title: do i want rolling_apply?
body: <p>I have a data frame that has a number of subjects completing a number of trials (1:800) and I want to add a "block" column...  There are 80 trials per block.  I feel like rolling_apply could be the solution, but I can't seem to make it work.</p>
  
  <p>I could do some sort of thing were every value of "trial" between two increments gets set at a certain block, but it seems like rolling_apply should do this.  I'd really like to do this, but it isn't possible:</p>
  
  <pre><code>grouped = df.groupby('sid')
  df['block'] = pd.rolling_cumcount(grouped, 80)
  </code></pre>
  
  <p>There are 10 blocks and 800 trials...</p>
  
  <pre><code>blocks = range(10)
  increments = range(800)[0::80]
  </code></pre>
  
  <p>I have this:</p>
  
  <pre><code>  SID  Trial  
      1    0      
      1    1      
      1    2      
      1    3      
      1    4      
      1    5      
      2    0      
      2    1      
      2    2      
      2    3      
      2    4      
      2    5  
  </code></pre>
  
  <p>What I want to end up with is (only I have 10 blocks, with 80 trials each):</p>
  
  <pre><code>SID  Trial  Block
  1    0      0
  1    1      0
  1    2      0
  1    3      1
  1    4      1
  1    5      1
  2    0      0
  2    1      0
  2    2      0
  2    3      1
  2    4      1
  2    5      1
  </code></pre>
  
  <p>Thanks</p>
  
  <hr>
  
  <p>I ended up just doing this, which probably isn't an optimal solution, but works fine:</p>
  
  <pre><code># add a block to each subject
  block = np.arange(1,11)
  block_array = np.repeat(block, 80)
  blocks_all = np.tile(block_array, df['sid'].nunique())
  df['block'] = blocks_all
  </code></pre>