Skip to content

Commit ab926b6

Browse files
committed
Fix & add clear doc for groupby
The old docs is wrong where head() & tail() return the same result. Change input of the example to see group data clearer. Remove as_index parameter has no effect with filter like head(),
1 parent 5fd1fbd commit ab926b6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pandas/core/groupby.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -997,16 +997,16 @@ def tail(self, n=5):
997997
Examples
998998
--------
999999
1000-
>>> df = DataFrame([[1, 2], [1, 4], [5, 6]],
1000+
>>> df = DataFrame([['a', 1], ['a', 2], ['b', 1], ['b', 2]],
10011001
columns=['A', 'B'])
1002-
>>> df.groupby('A', as_index=False).tail(1)
1002+
>>> df.groupby('A').tail(1)
10031003
A B
1004-
0 1 2
1005-
2 5 6
1004+
1 a 2
1005+
3 b 2
10061006
>>> df.groupby('A').head(1)
10071007
A B
1008-
0 1 2
1009-
2 5 6
1008+
0 a 1
1009+
2 b 1
10101010
10111011
"""
10121012
obj = self._selected_obj

0 commit comments

Comments
 (0)