title: pandas - merge and sum nearly duplicate rows
body: <p>I have a pandas data frame with several rows that are near-duplicates of each other, except for one value. my goal is to merge those rows and sum the distinct value.</p>
  <p>here is an example:</p>
  <pre><code>names   count   subject
  A       2       physics
  A       3       physics
  A       3       chemistry
  B       2       literature
  B       3       literature
  B       1       economics
  C       3       physics
  C       2       chemistry
  </code></pre>
  <p>And here is what I would like:</p>
  <pre><code>names   count   subject
  A       5       physics
  A       3       chemistry
  B       5       literature
  B       1       economics
  C       3       physics
  C       2       chemistry
  </code></pre>
  <p>i tried using the groupby() and this is what I got:</p>
  <pre><code>df2 = df.groupby([&quot;names&quot;,&quot;subject&quot;]).agg({&quot;count&quot;:&quot;sum&quot;})
  </code></pre>
  <pre><code>names subject       count
  A     chemistry       3
        physics         5
  B     economics       1
        literature      5
  C     chemistry       2
        physics         3
  
  </code></pre>
  <p>What would be the best way to tackle this issue? I've looked into the groupby() function but I still don't understand it very well.</p>