title: Pandas dataframe : Operation per batch of rows
body: <p>I have a pandas DataFrame <code>df</code> for which I want to compute some statistics per batch of rows. </p>
  
  <p>For example, let's say that I have a <code>batch_size = 200000</code>. </p>
  
  <p>For each batch of <code>batch_size</code> rows I would like to have the number of unique values for a column <code>ID</code> of my DataFrame.</p>
  
  <p>How can I do something like that ? </p>
  
  <p>Here is an example of what I want : </p>
  
  <pre><code>print(df)
  
  &gt;&gt;
  +-------+
  |     ID|
  +-------+
  |      1|
  |      1|
  |      2|
  |      2|
  |      2|
  |      3|
  |      3|
  |      3|
  |      3|
  +-------+
  
  batch_size = 3
  
  my_new_function(df,batch_size)
  
  &gt;&gt;
  For batch 1 (0 to 2) :
  2 unique values 
  1 appears 2 times
  2 appears 1 time
  
  For batch 2 (3 to 5) : 
  2 unique values 
  2 appears 2 times
  3 appears 1 time
  
  For batch 3 (6 to 8) 
  1 unique values 
  3 appears 3 times
  </code></pre>
  
  <p>Note : The output can of course be a simple DataFrame </p>