@Substitution(name='groupby')
    @Appender(_doc_template)
    def cumcount(self, ascending=True):

        self._set_selection_from_grouper()

        index = self._selected_obj.index
        cumcounts = self._cumcount_array(ascending=ascending)
        return Series(cumcounts, index)
Number each item in each group from 0 to the length of that group - 1.
dataset/ETHPy150Open pydata/pandas/pandas/core/groupby.py/GroupBy.cumcount