title: Python find out records in dataframe by column values greater than or equal to their median in each subgroup
body: <p>suppose I have  a dataframe  which could  be initiated by:</p>
  
  <pre><code>df = pd.DataFrame({'group1': ['1','2','3','4','5','6'],
                     'group2': ['c','c','d','d','d','e'],
                     'value1': [1.1,2,3,4,5,6],
                     'value2': [7.1,8,9,10,11,12]
                     })
  df = df.set_index(['group1', 'group2'])
  </code></pre>
  
  <p>I want to subset <code>df</code> by the <code>value2</code> column, the value of which is greater or equal to the median of each sub-group specified by the index of <code>group2</code>. In this example, the row of <code>group1</code> in <code>['2','4','5','6']</code> should stay in the result. Can anyone help?</p>