Pandas: groupby quantile with agg values
<p>I'm trying to group numerical values by quantiles and create columns for the sum of the values falling into the quantile bands. Here's a simplified, reproducible example:</p>

<pre><code>    raw_data = {'female': [0, 1, 0, 1, 0, 1, 0, 1],
        'male': [1, 0, 1, 0, 1, 0, 1, 0],
        'number': [25000, 34000, 48600, 22000, 50000, 21000, 29000, 36000]}
df = pd.DataFrame(raw_data, columns = ['female', 'male', 'number'])
df

    female  male    number
  0 0       1       25000
  1 1       0       34000
  2 0       1       48600
  3 1       0       22000
  4 0       1       50000
  5 1       0       21000
  6 0       1       29000
  7 1       0       36000
</code></pre>

<p>Essentially I'm trying to achieve this:</p>

<pre><code>pd.DataFrame(df['number'].quantile([.1, .2, .3, .4, .5]))

    number
0.1 21700
0.2 23200
0.3 25400
0.4 28200
0.5 31500
</code></pre>

<p>But in this dataframe show two new columns. One for the sum of males who's number falls into the corresponding quantile band and one for the sum of females. </p>

<p>Initially I thought this would be a <code>groupby</code> with <code>.quantile([values])</code> appended, and then <code>.agg({'male': 'sum', 'female':'sum'})</code> 
This doesn't work though. Can what I'm trying to achieve even be done?</p>