pandas 1.4.2

NotesReturns

groupby._positional_selector[i:j] is similar to groupby.apply(lambda x: x.iloc[i:j]) but much faster and preserves the original index and order.

_positional_selector[] is compatible with and extends ~GroupBy.head and ~GroupBy.tail . For example:

together return all the rows.

Allowed inputs for the index are:

The output format is the same as ~GroupBy.head and ~GroupBy.tail , namely a subset of the DataFrame or Series with the index and order preserved.

Notes

The differences between _positional_selector[] and ~GroupBy.nth with as_index=False are:

Returns

Series

The filtered subset of the original Series.

DataFrame

The filtered subset of the original DataFrame.

Return positional selection for each group.

See Also

DataFrame.iloc

Purely integer-location based indexing for selection by position.

GroupBy.head

Return first n rows of each group.

GroupBy.nth

Take the nth row from each group if n is an int, or a subset of rows, if n is a list of ints.

GroupBy.tail

Return last n rows of each group.

Examples

This example is valid syntax, but we were not able to check execution
>>> df = pd.DataFrame([["a", 1], ["a", 2], ["a", 3], ["b", 4], ["b", 5]],
...  columns=["A", "B"])
... df.groupby("A")._positional_selector[1:2] A B 1 a 2 4 b 5
This example is valid syntax, but we were not able to check execution
>>> df.groupby("A")._positional_selector[1, -1]
   A  B
1  a  2
2  a  3
4  b  5
See :

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/indexing.py#246
type: <class 'type'>
Commit: