@@ -2326,8 +2326,9 @@ def head(self, n=5):
2326
2326
"""
2327
2327
Return first n rows of each group.
2328
2328
2329
- Essentially equivalent to ``.apply(lambda x: x.head(n))``,
2330
- except ignores as_index flag.
2329
+ Similar to ``.apply(lambda x: x.head(n))``, but it returns a subset of rows
2330
+ from the original DataFrame with original index preserved (``as_index`` flag
2331
+ is ignored).
2331
2332
2332
2333
Returns
2333
2334
-------
@@ -2338,11 +2339,11 @@ def head(self, n=5):
2338
2339
2339
2340
>>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]],
2340
2341
... columns=['A', 'B'])
2341
- >>> df.groupby('A', as_index=False ).head(1)
2342
+ >>> df.groupby('A', as_index=True ).head(1)
2342
2343
A B
2343
2344
0 1 2
2344
2345
2 5 6
2345
- >>> df.groupby('A').head(1)
2346
+ >>> df.groupby('A', as_index=False ).head(1)
2346
2347
A B
2347
2348
0 1 2
2348
2349
2 5 6
@@ -2357,8 +2358,9 @@ def tail(self, n=5):
2357
2358
"""
2358
2359
Return last n rows of each group.
2359
2360
2360
- Essentially equivalent to ``.apply(lambda x: x.tail(n))``,
2361
- except ignores as_index flag.
2361
+ Similar to ``.apply(lambda x: x.tail(n))``, but it returns a subset of rows
2362
+ from the original DataFrame with original index preserved (``as_index`` flag
2363
+ is ignored).
2362
2364
2363
2365
Returns
2364
2366
-------
0 commit comments