Is there a simple way to manually iterate through existing pandas
groupby
objects?
import pandas as pd
df = pd.DataFrame({'x': [0, 1, 2, 3, 4], 'category': ['A', 'A', 'B', 'B', 'B']})
grouped = df.groupby('category')
In the application a for name, group in grouped:
loops follows. For manual-testing I would like to do something like group = grouped[0]
and run the code within the for-loop. Unfortunately this does not work. The best thing I could find (here) was
group = df[grouped.ngroup()==0]
which relies on the original DataFrame and not soley on the groupby-Object and is therefore not optimal imo.