Skip to content

Commit

Permalink
DOC: Adding example and See also to head and tail method (pandas-dev#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheukting committed Dec 13, 2017
1 parent 2a4f160 commit d59fba4
Showing 1 changed file with 41 additions and 33 deletions.
74 changes: 41 additions & 33 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3564,35 +3564,39 @@ def head(self, n=5):
obj_head : type of caller
The first n rows of the caller object.
See Also
--------
pandas.DataFrame.tail
Examples
--------
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
... 'monkey', 'shark', 'bee', 'bear']})
>>> df = pd.DataFrame({'animal':['bear', 'bee', 'falcon',
... 'lion', 'monkey', 'parrot', 'shark']})
>>> df
animal
0 falcon
1 parrot
2 lion
3 monkey
4 shark
5 bee
6 bear
0 bear
1 bee
2 falcon
3 lion
4 monkey
5 parrot
6 shark
Viewing the last 5 lines (the default)
>>> df.head()
animal
0 falcon
1 parrot
2 lion
3 monkey
4 shark
0 bear
1 bee
2 falcon
3 lion
4 monkey
Viewing the last n lines (three in this case)
>>> df.head(3)
animal
0 falcon
1 parrot
2 lion
0 bear
1 bee
2 falcon
"""

return self.iloc[:n]
Expand All @@ -3611,35 +3615,39 @@ def tail(self, n=5):
obj_tail : type of caller
The last n rows of the caller object.
See Also
--------
pandas.DataFrame.head
Examples
--------
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
... 'monkey', 'shark', 'bee', 'bear']})
>>> df
animal
0 falcon
1 parrot
2 lion
3 monkey
4 shark
5 bee
6 bear
0 bear
1 bee
2 falcon
3 lion
4 monkey
5 parrot
6 shark
Viewing the last 5 lines (the default)
>>> df.tail()
animal
2 lion
3 monkey
4 shark
5 bee
6 bear
2 falcon
3 lion
4 monkey
5 parrot
6 shark
Viewing the last n lines (three in this case)
>>> df.tail(3)
animal
4 shark
5 bee
6 bear
animal
4 monkey
5 parrot
6 shark
"""

Expand Down

0 comments on commit d59fba4

Please sign in to comment.