title: Pandas DataFrame: mean of column B values within column A windows
body: <p>If I have a pandas DataFrame in Python such as follows:</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  
  a = np.random.uniform(0,10,20)
  b = np.random.uniform(0,1,20)
  data = np.vstack([a,b]).T
  
  df = pd.DataFrame(data)
  df.columns = ['A','B']
  df.sort_values(by=['A'])
  
             A         B
  5   0.057519  0.465408
  14  1.610972  0.398077
  3   1.725556  0.397708
  17  1.734124  0.600723
  11  1.944105  0.694152
  19  3.265799  0.878538
  13  3.352460  0.770505
  10  3.865299  0.064723
  16  4.137863  0.659662
  12  5.597172  0.122269
  7   5.990105  0.667533
  6   6.410582  0.193027
  9   6.881429  0.041691
  15  7.522877  0.268144
  1   8.093155  0.130559
  0   8.699004  0.996624
  8   8.755095  0.495984
  4   9.135271  0.792966
  18  9.440045  0.477514
  2   9.654226  0.509812
  </code></pre>
  
  <p>Is it possible to efficiently calculate the mean of column <code>B</code> values in intervals of column <code>A</code>?</p>
  
  <p>For example one might want to calculate the mean of values in column <code>B</code> which fall into the bin ranges <code>[0,1,2,3,4,5,6,7,8,9,10]</code> of column <code>A</code>. So for the bin range <code>A = {0-1}</code> the mean of <code>B</code> values falling within this bin would be <code>0.465408</code>, for the bin range <code>A = {1-2}</code> the mean of B values falling within this bin would be <code>0.522665</code>, etc. </p>
  
  <p>I've found <code>pandas.core.window.Rolling.mean</code> (see <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.window.Rolling.mean.html" rel="noreferrer">https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.window.Rolling.mean.html</a>) but it appears to calculate the mean values over a window of specified length rather than over bin widths of another column. </p>