Skip to content

Commit

Permalink
DOC: Adding example to head and tail method (pandas-dev#16416)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheukting committed Dec 13, 2017
1 parent 96439fb commit 2a4f160
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions pandas/core/generic.py
Expand Up @@ -3563,6 +3563,36 @@ def head(self, n=5):
-------
obj_head : type of caller
The first n rows of the caller object.
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
Viewing the last 5 lines (the default)
>>> df.head()
animal
0 falcon
1 parrot
2 lion
3 monkey
4 shark
Viewing the last n lines (three in this case)
>>> df.head(3)
animal
0 falcon
1 parrot
2 lion
"""

return self.iloc[:n]
Expand All @@ -3580,6 +3610,37 @@ def tail(self, n=5):
-------
obj_tail : type of caller
The last n rows of the caller object.
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
Viewing the last 5 lines (the default)
>>> df.tail()
animal
2 lion
3 monkey
4 shark
5 bee
6 bear
Viewing the last n lines (three in this case)
>>> df.tail(3)
animal
4 shark
5 bee
6 bear
"""

if n == 0:
Expand Down

0 comments on commit 2a4f160

Please sign in to comment.