pydata/pandas — pull request #7910 by mortada (2014-08-03 21:20:30+00:00)
Title: added support for selecting multiple nth values

I'm not 100% sure this is the best way to implement this, but I think it'd be nice for GroupBy.nth() to support selecting multiple values. For instance if we have

df = DataFrame(1, index=pd.date_range(start='1/1/2013', end='6/30/2014', freq='B'), columns=['a', 'b'])

and currently we can easily get the nth entry for each month by:

df.groupby((df.index.year, df.index.month)).nth(0)

however we can't easily get, for instance, the first 5 entries for each group without having a more complex loop in the user code. If nth() accepts a list of integers we would be able to simply do

df.groupby((df.index.year, df.index.month)).nth(range(5))

This PR makes the above work when there's no dropna. I can't quite figure out the section where dropna is handled, and therefore I'm currently requiring that no dropna be passed when n is a list of values. I'm happy to improve this and also enhance the tests. Please let me know your feedback. Thanks.