title: Merge rows with the same values Pandas
body: <p>I have a pandas dataframe as follows:</p>
  
  <p><a href="https://i.stack.imgur.com/q8m37.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q8m37.png" alt="enter image description here"></a></p>
  
  <p>You will note here that there are many rows with the same <code>code_module,code_presentation,id_student</code> combination
  What I want to do is merge all of these duplicate rows, and in so sum the <code>sum_clicks</code> with each group</p>
  
  <p>An example of this is for the top rows they would be merged into one row looking as follows:</p>
  
  <pre><code>         code_module code_presentation  id_student  sum_click
  0                AAA             2013J       28400          18
  </code></pre>
  
  <p>In SQL terms, the private key should be a <code>code_module,code_presentation,id_student</code> combination</p>
  
  <p>In my progress on this, I tried to use groupby in the following way:</p>
  
  <pre class="lang-py prettyprint-override"><code>groupby(['id_student','code_presentation','code_module']).aggregate({'sum_click': 'sum',})
  </code></pre>
  
  <p>But this didn't work as it gave student ids that aren't even in my dataset, which I don't understand why</p>
  
  <p>Also, groupby doesn't seem to be quite what I'm looking for as it has a datastructure different to a standard pandas dataframe, which is what I would be looking for.</p>
  
  <p>The problem can be seen in the following output</p>
  
  <pre><code>                                        sum_click
  id_student code_presentation code_module           
  6516       2014J             AAA               2791
  8462       2013J             DDD                646
            2014J             DDD                 10
  11391      2013J             AAA                934
  </code></pre>
  
  <p>Row 1 and 2 (indexing from 0) should be distinct rows, instead of the group as they are</p>