@@ -2326,8 +2326,9 @@ def head(self, n=5):
23262326 """
23272327 Return first n rows of each group.
23282328
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).
23312332
23322333 Returns
23332334 -------
@@ -2338,11 +2339,11 @@ def head(self, n=5):
23382339
23392340 >>> df = pd.DataFrame([[1, 2], [1, 4], [5, 6]],
23402341 ... columns=['A', 'B'])
2341- >>> df.groupby('A', as_index=False ).head(1)
2342+ >>> df.groupby('A', as_index=True ).head(1)
23422343 A B
23432344 0 1 2
23442345 2 5 6
2345- >>> df.groupby('A').head(1)
2346+ >>> df.groupby('A', as_index=False ).head(1)
23462347 A B
23472348 0 1 2
23482349 2 5 6
@@ -2357,8 +2358,9 @@ def tail(self, n=5):
23572358 """
23582359 Return last n rows of each group.
23592360
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).
23622364
23632365 Returns
23642366 -------
0 commit comments