Using groupby and querying that group

I have a dataframe that I would like to group by one column (dadate) and then query another column (Place) to count only those with the value 1.

Leaguedata.groupby(['dadate']).query('Place == "1"').Place.count()`

The above is what I have tired with the error "'DataFrameGroupBy' object has no attribute 'query'"

1 answer

  • answered 2021-05-14 15:21 ALollz

    Create the Boolean Series then sum that within group to see how many Places == 1 for each group.

    Leaguedata['Place'].eq('1').groupby(Leaguedata['dadate']).sum()