Skip to content

Commit 2a4f160

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

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

pandas/core/generic.py

+61
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,36 @@ def head(self, n=5):
35633563
-------
35643564
obj_head : type of caller
35653565
The first n rows of the caller object.
3566+
3567+
Examples
3568+
--------
3569+
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
3570+
... 'monkey', 'shark', 'bee', 'bear']})
3571+
>>> df
3572+
animal
3573+
0 falcon
3574+
1 parrot
3575+
2 lion
3576+
3 monkey
3577+
4 shark
3578+
5 bee
3579+
6 bear
3580+
3581+
Viewing the last 5 lines (the default)
3582+
>>> df.head()
3583+
animal
3584+
0 falcon
3585+
1 parrot
3586+
2 lion
3587+
3 monkey
3588+
4 shark
3589+
3590+
Viewing the last n lines (three in this case)
3591+
>>> df.head(3)
3592+
animal
3593+
0 falcon
3594+
1 parrot
3595+
2 lion
35663596
"""
35673597

35683598
return self.iloc[:n]
@@ -3580,6 +3610,37 @@ def tail(self, n=5):
35803610
-------
35813611
obj_tail : type of caller
35823612
The last n rows of the caller object.
3613+
3614+
Examples
3615+
--------
3616+
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
3617+
... 'monkey', 'shark', 'bee', 'bear']})
3618+
>>> df
3619+
animal
3620+
0 falcon
3621+
1 parrot
3622+
2 lion
3623+
3 monkey
3624+
4 shark
3625+
5 bee
3626+
6 bear
3627+
3628+
Viewing the last 5 lines (the default)
3629+
>>> df.tail()
3630+
animal
3631+
2 lion
3632+
3 monkey
3633+
4 shark
3634+
5 bee
3635+
6 bear
3636+
3637+
Viewing the last n lines (three in this case)
3638+
>>> df.tail(3)
3639+
animal
3640+
4 shark
3641+
5 bee
3642+
6 bear
3643+
35833644
"""
35843645

35853646
if n == 0:

0 commit comments

Comments
 (0)