title: Binning a python pandas dataframe: extracting bin centers and the sum of another column
body: <p>I am having a bit of trouble binning a pandas dataframe and then extracting the necessary plotting variables.</p>
  
  <p>I have a pandas dataframe like the following:</p>
  
  <pre><code>            a    ad    td  price  result  profit_loss  
  12935   10809 -1181  2363    262     1.0     616743.0  
  13025  -18771   696  1390    350     1.0       1390.0  
  13079  -20154   348   695    305     0.0        695.0  
  13085    2370  3945  3150    264     0.0    -828450.0 
  </code></pre>
  
  <p>I want to bin the rows of the dataframe into equal sized bins of the "td" field (e.g. td = 0-100, 100-200, 200-300) and calculate the sum of all the profit_loss entries that fall into that td bin</p>
  
  <p>e.g. here, for a td bin from 0-2000 the profit_loss would be 1390+695.</p>
  
  <p>I then want to plot the td bin centers versus the profit_loss sums.</p>
  
  <p>I have tried:</p>
  
  <pre><code>bins = np.linspace(df.td.min(), df.td.max(), 10)
  groups = df.groupby(pd.cut(df.td, bins))
  </code></pre>
  
  <p>But I'm not sure how to extract the td bin centers and profit_loss sums created and plot them.</p>
  
  <p>Thanks! </p>