In [13]: df.groupby(["item", "color"])["id"].transform("count") Out[13]: 0 2 1 2 2 2 3 1 4 2 dtype: int64