upby.SeriesGroupBy.rolling ](pandas.core.groupby.SeriesGroupBy.rolling.html)
    * [ pandas.core.groupby.SeriesGroupBy.sample ](pandas.core.groupby.SeriesGroupBy.sample.html)
    * [ pandas.core.groupby.SeriesGroupBy.sem ](pandas.core.groupby.SeriesGroupBy.sem.html)
    * [ pandas.core.groupby.SeriesGroupBy.shift ](pandas.core.groupby.SeriesGroupBy.shift.html)
    * [ pandas.core.groupby.SeriesGroupBy.size ](pandas.core.groupby.SeriesGroupBy.size.html)
    * [ pandas.core.groupby.SeriesGroupBy.skew ](pandas.core.groupby.SeriesGroupBy.skew.html)
    * [ pandas.core.groupby.SeriesGroupBy.std ](pandas.core.groupby.SeriesGroupBy.std.html)
    * [ pandas.core.groupby.SeriesGroupBy.sum ](pandas.core.groupby.SeriesGroupBy.sum.html)
    * [ pandas.core.groupby.SeriesGroupBy.var ](pandas.core.groupby.SeriesGroupBy.var.html)
    * [ pandas.core.groupby.SeriesGroupBy.tail ](pandas.core.groupby.SeriesGroupBy.tail.html)
    * [ pandas.core.groupby.SeriesGroupBy.take ](pandas.core.groupby.SeriesGroupBy.take.html)
    * [ pandas.core.groupby.SeriesGroupBy.value_counts ](pandas.core.groupby.SeriesGroupBy.value_counts.html)
    * [ pandas.core.groupby.DataFrameGroupBy.boxplot ](pandas.core.groupby.DataFrameGroupBy.boxplot.html)
    * [ pandas.core.groupby.DataFrameGroupBy.hist ](pandas.core.groupby.DataFrameGroupBy.hist.html)
    * [ pandas.core.groupby.SeriesGroupBy.hist ](pandas.core.groupby.SeriesGroupBy.hist.html)
    * [ pandas.core.groupby.DataFrameGroupBy.plot ](pandas.core.groupby.DataFrameGroupBy.plot.html)
    * [ pandas.core.groupby.SeriesGroupBy.plot ](pandas.core.groupby.SeriesGroupBy.plot.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ GroupBy ](../groupby.html)
  * pandas.core.... 

#  pandas.core.groupby.SeriesGroupBy.cumcount  #

SeriesGroupBy.  cumcount  (  _ ascending  =  True  _ )  [ [source]
](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/groupby/groupby.py#L4649-L4706) #

    

Number each item in each group from 0 to the length of that group - 1.

Essentially this is equivalent to

    
    
    self.apply(lambda x: pd.Series(np.arange(len(x)), x.index))
    

Parameters  :

    

**ascending** bool, default True

    

If False, number in reverse, from length of group - 1 to 0.

Returns  :

    

Series

    

Sequence number of each element within each group.

See also

[ ` ngroup  `
](pandas.core.groupby.SeriesGroupBy.ngroup.html#pandas.core.groupby.SeriesGroupBy.ngroup
"pandas.core.groupby.SeriesGroupBy.ngroup")

    

Number the groups themselves.

Examples

    
    
    >>> df = pd.DataFrame([['a'], ['a'], ['a'], ['b'], ['b'], ['a']],
    ...                   columns=['A'])
    >>> df
       A
    0  a
    1  a
    2  a
    3  b
    4  b
    5  a
    >>> df.groupby('A').cumcount()
    0    0
    1    1
    2    2
    3    0
    4    1
    5    3
    dtype: int64
    >>> df.groupby('A').cumcount(ascending=False)
    0    3
    1    2
    2    1
    3    1
    4    0
    5    0
    dtype: int64
    

[ __ previous  pandas.core.groupby.SeriesGroupBy.cov
](pandas.core.groupby.SeriesGroupBy.cov.html "previous page") [ next
pandas.core.groupby.SeriesGroupBy.cummax  __
](pandas.core.groupby.SeriesGroupBy.cummax.html "next page")

__ On this page

  * ` SeriesGroupBy.cumcount()  `

[ __ Show Source
](../../_sources/reference/api/pandas.core.groupby.SeriesGroupBy.cumcount.rst.txt)

© 2024, pandas via [ NumFOCUS, Inc. ](https://numfocus.org) Hosted by [
OVHcloud ](https://www.ovhcloud.com) .

Created using [ Sphinx ](https://www.sphinx-doc.org/) 7.2.6.  

Built with the [ PyData Sphinx Theme ](https://pydata-sphinx-
theme.readthedocs.io/en/stable/index.html) 0.14.4.