Skip to content

Commit 241a336

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

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

pandas/core/generic.py

+69
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,40 @@ 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':['bear', 'bee', 'falcon',
3574+
... 'lion', 'monkey', 'parrot', 'shark']})
3575+
>>> df
3576+
animal
3577+
0 bear
3578+
1 bee
3579+
2 falcon
3580+
3 lion
3581+
4 monkey
3582+
5 parrot
3583+
6 shark
3584+
3585+
Viewing the first 5 lines
3586+
>>> df.head()
3587+
animal
3588+
0 bear
3589+
1 bee
3590+
2 falcon
3591+
3 lion
3592+
4 monkey
3593+
3594+
Viewing the first n lines (three in this case)
3595+
>>> df.head(3)
3596+
animal
3597+
0 bear
3598+
1 bee
3599+
2 falcon
35663600
"""
35673601

35683602
return self.iloc[:n]
@@ -3580,6 +3614,41 @@ def tail(self, n=5):
35803614
-------
35813615
obj_tail : type of caller
35823616
The last n rows of the caller object.
3617+
3618+
See Also
3619+
--------
3620+
pandas.DataFrame.head
3621+
3622+
Examples
3623+
--------
3624+
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
3625+
... 'monkey', 'shark', 'bee', 'bear']})
3626+
>>> df
3627+
animal
3628+
0 bear
3629+
1 bee
3630+
2 falcon
3631+
3 lion
3632+
4 monkey
3633+
5 parrot
3634+
6 shark
3635+
3636+
Viewing the last 5 lines
3637+
>>> df.tail()
3638+
animal
3639+
2 falcon
3640+
3 lion
3641+
4 monkey
3642+
5 parrot
3643+
6 shark
3644+
3645+
Viewing the last n lines (three in this case)
3646+
>>> df.tail(3)
3647+
animal
3648+
4 monkey
3649+
5 parrot
3650+
6 shark
3651+
35833652
"""
35843653

35853654
if n == 0:

0 commit comments

Comments
 (0)