From d59fba4d1223b194205eba256703f6fed9c4ab7e Mon Sep 17 00:00:00 2001 From: Cheuk Ho Date: Wed, 13 Dec 2017 15:40:42 +0000 Subject: [PATCH] DOC: Adding example and See also to head and tail method (#16416) --- pandas/core/generic.py | 74 +++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index e828dce3654e35..2468f4fc406c13 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -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] @@ -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 """