Skip to content

Commit d59fba4

Browse files
committed
DOC: Adding example and See also to head and tail method (#16416)
1 parent 2a4f160 commit d59fba4

File tree

1 file changed

+41
-33
lines changed

1 file changed

+41
-33
lines changed

pandas/core/generic.py

+41-33
Original file line numberDiff line numberDiff line change
@@ -3564,35 +3564,39 @@ def head(self, n=5):
35643564
obj_head : type of caller
35653565
The first n rows of the caller object.
35663566
3567+
See Also
3568+
--------
3569+
pandas.DataFrame.tail
3570+
35673571
Examples
35683572
--------
3569-
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
3570-
... 'monkey', 'shark', 'bee', 'bear']})
3573+
>>> df = pd.DataFrame({'animal':['bear', 'bee', 'falcon',
3574+
... 'lion', 'monkey', 'parrot', 'shark']})
35713575
>>> df
35723576
animal
3573-
0 falcon
3574-
1 parrot
3575-
2 lion
3576-
3 monkey
3577-
4 shark
3578-
5 bee
3579-
6 bear
3577+
0 bear
3578+
1 bee
3579+
2 falcon
3580+
3 lion
3581+
4 monkey
3582+
5 parrot
3583+
6 shark
35803584
35813585
Viewing the last 5 lines (the default)
35823586
>>> df.head()
35833587
animal
3584-
0 falcon
3585-
1 parrot
3586-
2 lion
3587-
3 monkey
3588-
4 shark
3588+
0 bear
3589+
1 bee
3590+
2 falcon
3591+
3 lion
3592+
4 monkey
35893593
35903594
Viewing the last n lines (three in this case)
35913595
>>> df.head(3)
35923596
animal
3593-
0 falcon
3594-
1 parrot
3595-
2 lion
3597+
0 bear
3598+
1 bee
3599+
2 falcon
35963600
"""
35973601

35983602
return self.iloc[:n]
@@ -3611,35 +3615,39 @@ def tail(self, n=5):
36113615
obj_tail : type of caller
36123616
The last n rows of the caller object.
36133617
3618+
See Also
3619+
--------
3620+
pandas.DataFrame.head
3621+
36143622
Examples
36153623
--------
36163624
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
36173625
... 'monkey', 'shark', 'bee', 'bear']})
36183626
>>> df
36193627
animal
3620-
0 falcon
3621-
1 parrot
3622-
2 lion
3623-
3 monkey
3624-
4 shark
3625-
5 bee
3626-
6 bear
3628+
0 bear
3629+
1 bee
3630+
2 falcon
3631+
3 lion
3632+
4 monkey
3633+
5 parrot
3634+
6 shark
36273635
36283636
Viewing the last 5 lines (the default)
36293637
>>> df.tail()
36303638
animal
3631-
2 lion
3632-
3 monkey
3633-
4 shark
3634-
5 bee
3635-
6 bear
3639+
2 falcon
3640+
3 lion
3641+
4 monkey
3642+
5 parrot
3643+
6 shark
36363644
36373645
Viewing the last n lines (three in this case)
36383646
>>> df.tail(3)
3639-
animal
3640-
4 shark
3641-
5 bee
3642-
6 bear
3647+
animal
3648+
4 monkey
3649+
5 parrot
3650+
6 shark
36433651
36443652
"""
36453653

0 commit comments

Comments
 (0)