title: idxmax() doesn't work on SeriesGroupBy that contains NaN
body: <p>Here is my code</p>
  
  <pre><code>from pandas import DataFrame, Series
  import pandas as pd
  import numpy as np
  income = DataFrame({'name': ['Adam', 'Bill', 'Chris', 'Dave', 'Edison', 'Frank'],
                      'age': [22, 24, 31, 45, 51, 55],
                      'income': [1000, 2500, 1200, 1500, 1300, 1600],
                      })
  ageBin = pd.cut(income.age, [20, 30, 40, 50, 60])
  grouped = income.groupby([ageBin])
  highestIncome = income.ix[grouped.income.idxmax()]
  </code></pre>
  
  <p>I have a DataFrame that contains names, ages and income as follows:</p>
  
  <pre><code>index   age income  name
  0   22  1000    Adam
  1   24  2500    Bill
  2   31  1200    Chris
  3   45  1500    Dave
  4   51  1300    Edison
  5   55  1600    Frank
  </code></pre>
  
  <p>I would like to group the data by the age bins and collect the records with highest income. The code above works and the <code>highestIncome</code> is:</p>
  
  <pre><code>index   age income  name
  1   24  2500    Bill
  2   31  1200    Chris
  3   45  1500    Dave
  5   55  1600    Frank
  </code></pre>
  
  <p>However, if I delete the record of Chris and thus there is no record within the age range of <em>(30, 40]</em>, I get a <code>ValueError</code> at <code>grouped.income.idxmax()</code>. I think this is because of the <code>NaN</code> in grouped, but I cannot find a way to solve the problem. Any input is appreciated.</p>
  
  <p><strong>Update:</strong> Thanks a lot for the answers. I do believe this is a bug on idxmax() for groupby objects. I would like to go with the <code>agg(lambda x: x.idxmax())</code> approach as I did a test of the speed of using <code>sort()</code> vs <code>agg(lambda x: x.idxmax()</code> on a 10 million synthetic data set. Here is the code and the output:</p>
  
  <pre><code>from pandas import DataFrame, Series
  import pandas as pd
  import numpy as np
  import time
  
  testData = DataFrame({'key': np.random.randn(10000000),
                        'value': np.random.randn(10000000)})
  keyBin = pd.cut(testData.key, 1000)
  
  start = time.time()
  grouped1 = testData.sort('value', ascending=False).groupby([keyBin])
  highestValues1 = testData.ix[grouped1.head(1).index]
  end = time.time()
  print end - start
  
  start = time.time()
  grouped2 = testData.groupby([keyBin])
  highestValues2 = testData.ix[grouped2.value.agg(lambda x: x.idxmax())].dropna(how='all')
  end = time.time()
  print end - start
  #validation
  (highestValues1.sort() == highestValues2.sort()).all()
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>5.30953717232
  1.0279238224
  
  Out[47]:
  
  key      True
  value    True
  dtype: bool
  </code></pre>