roupby.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.ngroup  #

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

    

Number each group from 0 to the number of groups - 1.

This is the enumerative complement of cumcount. Note that the numbers given to
the groups match the order in which the groups would be seen when iterating
over the groupby object, not the order they are first observed.

Groups with missing keys (where  pd.isna()  is True) will be labeled with  NaN
and will be skipped from the count.

Parameters  :

    

**ascending** bool, default True

    

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

Returns  :

    

Series

    

Unique numbers for each group.

See also

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

    

Number the rows in each group.

Examples

    
    
    >>> df = pd.DataFrame({"color": ["red", None, "red", "blue", "blue", "red"]})
    >>> df
       color
    0    red
    1   None
    2    red
    3   blue
    4   blue
    5    red
    >>> df.groupby("color").ngroup()
    0    1.0
    1    NaN
    2    1.0
    3    0.0
    4    0.0
    5    1.0
    dtype: float64
    >>> df.groupby("color", dropna=False).ngroup()
    0    1
    1    2
    2    1
    3    0
    4    0
    5    1
    dtype: int64
    >>> df.groupby("color", dropna=False).ngroup(ascending=False)
    0    1
    1    0
    2    1
    3    2
    4    2
    5    1
    dtype: int64
    

[ __ previous  pandas.core.groupby.SeriesGroupBy.min
](pandas.core.groupby.SeriesGroupBy.min.html "previous page") [ next
pandas.core.groupby.SeriesGroupBy.nlargest  __
](pandas.core.groupby.SeriesGroupBy.nlargest.html "next page")

__ On this page

  * ` SeriesGroupBy.ngroup()  `

[ __ Show Source
](../../_sources/reference/api/pandas.core.groupby.SeriesGroupBy