wesm/pandas — Issue #307: ENH: Add .topK(col, k) to DataFrame
Author: hammer
Created: 2011-10-29 07:26:37+00:00
State: open

When exploring new datasets in pandas, I often find myself writing
```df.groupby(col)[col].agg(len).order(ascending=False).head()```.

I added a convenience method to frame.py so that I could write ```df.topK(col)``` instead:

```python
def topK(self, col, k=5):
"""Returns top k most frequently occurring values in column col
"""
return self.groupby(col)[col].agg(len).order(ascending=False).head(k)
```