def count(self):
        ids, _, ngroups = self.grouper.group_info
        val = self.obj.get_values()

        mask = (ids != -1) & ~isnull(val)
        ids = com._ensure_platform_int(ids)
        out = np.bincount(ids[mask], minlength=ngroups or None)

        return Series(out,
                      index=self.grouper.result_index,
                      name=self.name,
                      dtype='int64')
Compute count of group, excluding missing values
dataset/ETHPy150Open pydata/pandas/pandas/core/groupby.py/SeriesGroupBy.count