ajayramesh
ajayramesh

Reputation: 3774

count with a function in panda

I am having real fun with groupby function in pandas, please advice on how to apply functions on groupby? Such as, I want to know how many rows grouped by track_id satisfies the rule_1==4 or anything in general.

df.groupby('track_id')['rule_1'].count()

I want to know rule_1 which equals some value.

I tried this - df.groupby('track_id')['rule_1'==4].count()

Is there a callback function or anything simpler ?

Upvotes: 1

Views: 33

Answers (1)

BENY
BENY

Reputation: 323226

Check

df['rule_1'].eq(4).groupby(df['track_id']).sum()

Upvotes: 3

Related Questions