pandas 1.4.2

ParametersReturnsBackRef
cumcount(self, ascending: 'bool' = True)

Essentially this is equivalent to

.. code-block:: python
    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.

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

See Also

.ngroup

Number the groups themselves.

Examples

This example is valid syntax, but we were not able to check execution
>>> 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
This example is valid syntax, but we were not able to check execution
>>> df.groupby('A').cumcount()
0    0
1    1
2    2
3    0
4    1
5    3
dtype: int64
This example is valid syntax, but we were not able to check execution
>>> df.groupby('A').cumcount(ascending=False)
0    3
1    2
2    1
3    1
4    0
5    0
dtype: int64
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.groupby.groupby.GroupBy.ngroup

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/groupby/groupby.py#3040
type: <class 'function'>
Commit: