Skip to content

Commit 018aad7

Browse files
committed
DOC: Adding example and See also to head and tail method (#16416)
1 parent 96439fb commit 018aad7

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

pandas/core/generic.py

+72
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,42 @@ def head(self, n=5):
35633563
-------
35643564
obj_head : type of caller
35653565
The first n rows of the caller object.
3566+
3567+
See Also
3568+
--------
3569+
pandas.DataFrame.tail
3570+
3571+
Examples
3572+
--------
3573+
>>> df = pd.DataFrame({'animal':['alligator', 'bee', 'falcon', 'lion',
3574+
... 'monkey', 'parrot', 'shark', 'whale', 'zebra']})
3575+
>>> df
3576+
animal
3577+
0 alligator
3578+
1 bee
3579+
2 falcon
3580+
3 lion
3581+
4 monkey
3582+
5 parrot
3583+
6 shark
3584+
7 whale
3585+
8 zebra
3586+
3587+
Viewing the first 5 lines
3588+
>>> df.head()
3589+
animal
3590+
0 alligator
3591+
1 bee
3592+
2 falcon
3593+
3 lion
3594+
4 monkey
3595+
3596+
Viewing the first n lines (three in this case)
3597+
>>> df.head(3)
3598+
animal
3599+
0 alligator
3600+
1 bee
3601+
2 falcon
35663602
"""
35673603

35683604
return self.iloc[:n]
@@ -3580,6 +3616,42 @@ def tail(self, n=5):
35803616
-------
35813617
obj_tail : type of caller
35823618
The last n rows of the caller object.
3619+
3620+
See Also
3621+
--------
3622+
pandas.DataFrame.head
3623+
3624+
Examples
3625+
--------
3626+
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
3627+
... 'monkey', 'shark', 'bee', 'bear']})
3628+
>>> df
3629+
animal
3630+
0 alligator
3631+
1 bee
3632+
2 falcon
3633+
3 lion
3634+
4 monkey
3635+
5 parrot
3636+
6 shark
3637+
7 whale
3638+
8 zebra
3639+
3640+
Viewing the last 5 lines
3641+
>>> df.tail()
3642+
animal
3643+
4 monkey
3644+
5 parrot
3645+
6 shark
3646+
7 whale
3647+
8 zebra
3648+
3649+
Viewing the last n lines (three in this case)
3650+
>>> df.tail(3)
3651+
animal
3652+
6 shark
3653+
7 whale
3654+
8 zebra
35833655
"""
35843656

35853657
if n == 0:

0 commit comments

Comments
 (0)