@@ -2370,8 +2370,9 @@ def head(self, n=5):
23702370 """
23712371 Return first n rows of each group.
23722372
2373- Essentially equivalent to ``.apply(lambda x: x.head(n))``,
2374- except ignores as_index flag.
2373+ Similar to ``.apply(lambda x: x.head(n))``, but it returns a subset of rows
2374+ from the original DataFrame with original index and order preserved
2375+ (``as_index`` flag is ignored).
23752376
23762377 Returns
23772378 -------
@@ -2382,10 +2383,6 @@ def head(self, n=5):
23822383
23832384 >>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]],
23842385 ... columns=['A', 'B'])
2385- >>> df.groupby('A', as_index=False).head(1)
2386- A B
2387- 0 1 2
2388- 2 5 6
23892386 >>> df.groupby('A').head(1)
23902387 A B
23912388 0 1 2
@@ -2401,8 +2398,9 @@ def tail(self, n=5):
24012398 """
24022399 Return last n rows of each group.
24032400
2404- Essentially equivalent to ``.apply(lambda x: x.tail(n))``,
2405- except ignores as_index flag.
2401+ Similar to ``.apply(lambda x: x.tail(n))``, but it returns a subset of rows
2402+ from the original DataFrame with original index and order preserved
2403+ (``as_index`` flag is ignored).
24062404
24072405 Returns
24082406 -------
@@ -2417,10 +2415,6 @@ def tail(self, n=5):
24172415 A B
24182416 1 a 2
24192417 3 b 2
2420- >>> df.groupby('A').head(1)
2421- A B
2422- 0 a 1
2423- 2 b 1
24242418 """
24252419 self ._reset_group_selection ()
24262420 mask = self ._cumcount_array (ascending = False ) < n
0 commit comments