-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Add examples and notes to empty documentation #12442
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
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7abd759
Add examples and notes to empty documentation
masongallo f9ef74a
Change any to all
masongallo 59da0f9
Address feedback to include examples of empty and non-empty with NaNs
masongallo 30f09ea
Add see also section and replace i.e. with meaning
masongallo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -842,7 +842,43 @@ def __contains__(self, key): | |
|
||
@property | ||
def empty(self): | ||
"""True if NDFrame is entirely empty [no items]""" | ||
"""True if NDFrame is entirely empty [no items], meaning any of the | ||
axes are of length 0. | ||
|
||
Notes | ||
----- | ||
If NDFrame contains only NaNs, it is still not considered empty. See | ||
the example below. | ||
|
||
Examples | ||
-------- | ||
An example of an actual empty DataFrame. Notice the index is empty: | ||
|
||
>>> df_empty = pd.DataFrame({'A' : []}) | ||
>>> df_empty | ||
Empty DataFrame | ||
Columns: [A] | ||
Index: [] | ||
>>> df_empty.empty | ||
True | ||
|
||
If we only have NaNs in our DataFrame, it is not considered empty! We | ||
will need to drop the NaNs to make the DataFrame empty: | ||
|
||
>>> df = pd.DataFrame({'A' : [np.nan]}) | ||
>>> df | ||
A | ||
0 NaN | ||
>>> df.empty | ||
False | ||
>>> df.dropna().empty | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem as above about the comment + I would also show the output of the actual empty frame |
||
True | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a |
||
See also | ||
-------- | ||
pandas.Series.dropna | ||
pandas.DataFrame.dropna | ||
""" | ||
return not all(len(self._get_axis(a)) > 0 for a in self._AXIS_ORDERS) | ||
|
||
def __nonzero__(self): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be below examples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, do you mean move the entire notes section below examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is OK to leave it here (Jeff, in the html rendered version, the notes will also be before the examples, irregardless of how the order is here)