Pandas: calculating the mean values of duplicate entries in a dataframe
<p>I have been working with a dataframe in python and pandas that contains duplicate entries in the first column. The dataframe looks something like this:</p>

<pre><code>    sample_id    qual    percent
0   sample_1      10        20
1   sample_2      20        30
2   sample_1      50        60
3   sample_2      10        90
4   sample_3      100       20
</code></pre>

<p>I want to write something that identifies duplicate entries within the first column and calculates the mean values of the subsequent columns. An ideal output would be something similar to the following:</p>

<pre><code>    sample_id    qual    percent
0   sample_1      30        40
1   sample_2      15        60
2   sample_3      100       20
</code></pre>

<p>I have been struggling with this problem all afternoon and would appreciate any help.</p>

<p><code>groupby</code> the <code>sample_id</code> column and use <code>mean</code></p>

<p><code>df.groupby('sample_id').mean().reset_index()</code><br>
<strong><em>or</em></strong><br>
<code>df.groupby('sample_id', as_index=False).mean()</code></p>

<p>get you </p>

<p><a href="http://i.stack.imgur.com/nw7e9.png" rel="nofollow"><img src="http://i.stack.imgur.com/nw7e9.png" alt="enter image description here"></a></p>

python pandas