title: How to filter a grouped DataFrame by maximum values in each group using Pandas?
body: <p><em>I hope you are doing well in the current situation</em></p>
  <p>I've the following dataFrame as an input:</p>
  <pre><code>df_0 = pd.DataFrame({&quot;year&quot; : [1960, 1960, 1960, 1960, 1961, 1961, 1961, 1962, 1962, 1962,],
                       &quot;genre&quot;: ['Action', 'Crime', 'Action', 'Drama', 'Thriller', 'Thriller', 'Crime', 'Drama', 'Drama', 'Thriller'],
                       &quot;popularity&quot;: [1.99, 0.53, 1.81, 0.23, 3.86, 3.94, 0.21, 4.30, 5.60, 0.09] })
  </code></pre>
  <p><strong>figure 0:</strong></p>
  <pre><code>        year    genre   popularity
  0       1960    Action    1.99
  1       1960    Crime     0.53
  2       1960    Action    1.81
  3       1960    Drama     0.23
  4       1961    Thriller  3.86
  5       1961    Thriller  3.94
  6       1961    Crime     0.21
  7       1962    Drama     4.30
  8       1962    Drama     5.60
  9       1962    Thriller  0.09
  </code></pre>
  <p>I've created a new dataFrame <code>df_1</code> by grouping by values like this:</p>
  <pre><code>df_1 = df_0.groupby(['year','genre']).popularity.agg(['mean','max'])
  </code></pre>
  <p><strong>figure 1:</strong></p>
  <pre><code>                    mean    max
  year    genre       
  1960    Action      1.90    1.99
          Crime       0.53    0.53
          Drama       0.23    0.23
  1961    Crime       0.21    0.21
          Thriller    3.90    3.94
  1962    Drama       4.95    5.60
          Thriller    0.09    0.09
  </code></pre>
  <p>As a result, we've got a similar dataFrame as the following:</p>
  <pre><code>df_1 = pd.DataFrame({&quot;year&quot; : [1960, 1960, 1960, 1961, 1961, 1962, 1962,],
                       &quot;genre&quot;: ['Action', 'Crime', 'Drama', 'Crime', 'Thriller', 'Drama', 'Thriller'],
                       &quot;mean &quot;: [1.90, 0.53, 0.23, 0.21, 3.90, 4.95, 0.09],
                       &quot;max&quot;  : [1.99, 0.53, 0.23, 0.21, 3.94, 5.60, 0.09] }).set_index(&quot;year&quot;)
  </code></pre>
  <p>And I'm struggling with the next steps.
  I would like to create the following dataFrame <code>df_2</code> from <code>df_1</code> <em>(.groupby())</em> using only pandas functions <em>(and no numpy or at the minimum)</em>:</p>
  <pre><code>df_2 = pd.DataFrame({&quot;year&quot; : [1960, 1961, 1962],
                       &quot;genre&quot;: ['Action', 'Thriller', 'Drama'],
                       &quot;mean &quot;: [1.90, 3.90, 4.95],
                       &quot;max&quot;  : [1.99, 3.94, 5.60] }).set_index(&quot;year&quot;)
  </code></pre>
  <p><strong>figure 2:</strong></p>
  <pre><code>        genre     mean  max
  year            
  1960    Action    1.90  1.99
  1961    Thriller  3.90  3.94
  1962    Drama     4.95  5.60
  </code></pre>
  <p><strong>This dataFrame <code>df_2</code> collects the maximum values of each group.</strong></p>
  <p>Any tips?<br />
  Thank you for your support.</p>
  <p><em>Stay safe</em></p>