Skip to content

DOC: Add note for tail/head when n is larger then length of DataFrame #46114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5162,6 +5162,9 @@ def head(self: NDFrameT, n: int = 5) -> NDFrameT:
For negative values of `n`, this function returns all rows except
the last `n` rows, equivalent to ``df[:-n]``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add something like if n is larger than the lenght of the DataFrame, the whole DataFrame is returned.

You can run pre-commit locally to avoid the pep8 issues

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


`n` can be larger than the object size (this conforms with python/numpy
slice semantics).

Parameters
----------
n : int, default 5
Expand Down Expand Up @@ -5235,6 +5238,9 @@ def tail(self: NDFrameT, n: int = 5) -> NDFrameT:
For negative values of `n`, this function returns all rows except
the first `n` rows, equivalent to ``df[n:]``.

`n` can be larger than the object size (this conforms with python/numpy
slice semantics).

Parameters
----------
n : int, default 5
Expand Down