title: Python 3- Group by for binned rows
body: <p>I have a df called exp with the following columns:</p>
  
  <pre><code>| category | p_value | score |
  | tennis   |  0.45   |  432  |
  | soccer   |  0.88   |  46   |
  </code></pre>
  
  <p>My goal is to bin all the scores per p value and create an accumulative plot that is grouped by category.</p>
  
  <p>I managed to create the bin using the following:</p>
  
  <pre><code># find the p_value bin, each row belongs to
  # 0 is underflow, len(edges) is overflow bin
  exp['bin'] = np.digitize(exp['p value'], bins=bin_edges)
  
  # get the number of UBI per p_value bin
  score_per_bin = exp.groupby('bin')['score'].sum()
  </code></pre>
  
  <p>And than managed to plot it:
   not every bin might be filled, so we will use pandas index</p>
  
  <pre><code>binned = pd.DataFrame({
      'center': bin_center,
      'width': bin_width,
      'score': np.zeros(len(bin_center))
  }, index=np.arange(1, len(bin_edges)))
  
  binned['score'] = score_per_bin
  
  
  plt.step(
      binned['center'],
      binned['score'].cumsum(),
      where='mid',
  )
  plt.xlabel('p-value')
  plt.ylabel('score')
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/RC7Gt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RC7Gt.png" alt="enter image description here"></a></p>
  
  <p>But I get a plot with 1 line while I need a line per category.
  My question is - how do I keep the category and plot it?</p>
  
  <p>Thank you</p>