Skip to content

Commit c28b624

Browse files
Cheuktingjreback
authored andcommitted
DOC: Adding example and See also to head and tail method (#16416) (#18749)
1 parent a845187 commit c28b624

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

Diff for: pandas/core/generic.py

+76
Original file line numberDiff line numberDiff line change
@@ -3563,6 +3563,44 @@ 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+
3589+
>>> df.head()
3590+
animal
3591+
0 alligator
3592+
1 bee
3593+
2 falcon
3594+
3 lion
3595+
4 monkey
3596+
3597+
Viewing the first n lines (three in this case)
3598+
3599+
>>> df.head(3)
3600+
animal
3601+
0 alligator
3602+
1 bee
3603+
2 falcon
35663604
"""
35673605

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

35853661
if n == 0:

0 commit comments

Comments
 (0)