I\'m looking for a way to get a list of all the keys in a GroupBy object, but I can\'t seem to find one via the docs nor through Google.
There is definitely a way t
A problem with EdChum's answer is that getting keys by launching gp.groups.keys()
first constructs the full group dictionary. On large dataframes, this is a very slow operation, which effectively doubles the memory consumption. Iterating is waaay faster:
df = pd.DataFrame({'group':list('bgaaabxeb'), 'val':np.arange(9)})
gp = df.groupby('group')
keys = [key for key, _ in gp]
Executing this list comprehension took me 16 s
on my groupby object, while I had to interrupt gp.groups.keys()
after 3 minutes.