I have a pandas dataframe
df.columns Index([u'car_id',u'color',u'make',u'year')]
I would like to create a new FILTERABLE object that has a counter for each group (color, year, year);
grp = df[['color','make','year']].groupby(['color','make','year']).size()
which will return something like this
color make year count black honda 2011 416
I would like to be able to filter it, however, when I try this:
grp.filter(lambda x: x['color']=='black')
I get this error
TypeError: object 'function' is not iterable
How can I use a groupby object to filter strings?
python pandas indexing group-by condition
chattrat423
source share