Iterate Over A Subset Of A Pandas Groupby Object
I have a Pandas groupby object, and I would like to iterate over the first n groups. I've tried: import pandas as pd df = pd.DataFrame({'A':['a','a','a','b','b','c','c','c','c','d'
Solution 1:
You can filter with your original df, then we can do all the other you need to do
yourdf=df[df.groupby('A').ngroup()<=1]
yourdf=df[pd.factorize(df.A)[0]<=1]
Post a Comment for "Iterate Over A Subset Of A Pandas Groupby Object"