Pass in as_index=False
to the groupby, then you don’t need to reset_index
to make the groupby-d columns columns again:
In [11]: grouped = df.groupby('A', as_index=False)
In [12]: grouped.get_group('foo')
Out[12]:
A B
0 foo 1
2 foo 3
4 foo 5
6 foo 7
7 foo 8
Note: As pointed out (and seen in the above example) the index above is not [0, 1, 2, ...]
, I claim that this will never matter in practice – if it does you’re going to have to just through some strange hoops – it’s going to be more verbose, less readable and less efficient…