Pandas, filter max values by row and columns
<p>I have this dataframe.</p>

<pre><code>In [6]: df
Out[6]:
    Beam  Pos Comb   As  
0    B1    1    1    3          
1    B1    1    1    2          
2    B1    2    1    5          
3    B1    2    1    8          
4    B1    1    2    10         
5    B1    1    2    1         
6    B1    2    2    3          
7    B1    2    2    2
8    B2    1    1    1          
9    B2    1    1    2          
10   B2    2    1    5          
11   B2    2    1    6          
12   B2    1    2    8         
13   B2    1    2    1         
14   B2    2    2    3          
15   B2    2    2    2           
</code></pre>

<p>I need to get the max value per beam and position searching in diferent combinations.</p>

<pre><code>    Beam  Pos Comb   As
0    B1    1    2    10         
1    B1    2    1    8         
2    B2    1    2    8          
3    B2    2    1    6  
</code></pre>

<p>I can't figured out how can I compare the "As" values for Beam, position and combination.</p>

<p>Perhaps grouping the beam, the positions and then get the max value?</p>

<p>Any help will be appreciated     </p>

<p>you have to use the <code>groupby</code> method on the multi level index:</p>

<pre><code>d = df.groupby(by= [ "Beam",  "Pos", "Comb"])
g=d.agg({"As":"max"})
g.reset_index(inplace=True)
</code></pre>

<p>the first line groups together the items that have the same <code>(Beam,Pos,Comb)</code> index,
the second line select the max <code>As</code> on each group and the <code>reset_index</code> undo the groups in the dataframe</p>

python pandas filter group