select df.id, count(distinct airports) as num
from df
group by df.id
having count(distinct airports) > 3
I'm trying to do the equivalent of the above in Python pandas. I've tried different combinations of filter
, nunique
, agg
, and nothing is working. Any advice?
ex: df
df
id airport
1 lax
1 ohare
2 phl
3 lax
2 mdw
2 lax
2 sfw
2 tpe
So I want the result to be:
id num
2 5