<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def cumcount(self, ascending=True):
 """ Number each item in each group from 0 to the length of that group - 1. Essentially this is equivalent to Parameters ascending : bool, default True If False, number in reverse, from length of group - 1 to 0. See Also -------- .ngroup : Number the groups themselves. Examples -------- A 0 a 1 a 2 a 3 b 4 b 5 a 0 0 1 1 2 2 3 0 4 1 5 3 dtype: int64 0 3 1 2 2 1 3 1 4 0 5 0 dtype: int64 """


        with _group_selection_context(self):
            index = self._selected_obj.index
            cumcounts = self._cumcount_array(ascending=ascending)
            return Series(cumcounts, index)