Skip to content

updated empty in pandas.DataFrame.empty or pandas.Series.empty docstrings #42709

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
31 changes: 23 additions & 8 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,15 +1934,15 @@ def __contains__(self, key) -> bool_t:
@property
def empty(self) -> bool_t:
"""
Indicator whether DataFrame is empty.
Indicator whether Series or DataFrame is empty.

True if DataFrame is entirely empty (no items), meaning any of the
True if Series or DataFrame is entirely empty (no items), meaning any of the
axes are of length 0.

Returns
-------
bool
If DataFrame is empty, return True, if not return False.
If Series or DataFrame is empty, return True, if not return False.

See Also
--------
Expand All @@ -1952,23 +1952,32 @@ def empty(self) -> bool_t:

Notes
-----
If DataFrame contains only NaNs, it is still not considered empty. See
If Series or DataFrame 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:
An example of an actual empty Series or DataFrame. Notice the index is empty:

>>> df_empty = pd.DataFrame({'A' : []})
>>> df_empty
>>> print(df_empty)
Empty DataFrame
Columns: [A]
Index: []
>>> df_empty.empty
True
>>> df_empty = pd.Series({'A' : []})
>>> df_empty
A []
dtype: object
>>> df_empty.empty
False
>>> df_empty = pd.Series()
>>> 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:
If we only have NaNs in our Series or DataFrame, it is not considered empty! We
will need to drop the NaNs to make the Series or DataFrame empty:

>>> df = pd.DataFrame({'A' : [np.nan]})
>>> df
Expand All @@ -1978,6 +1987,12 @@ def empty(self) -> bool_t:
False
>>> df.dropna().empty
True
>>> df = pd.Series({'A' : [np.nan]})
>>> df
A [nan]
dtype: object
>>> df.empty
False
"""
return any(len(self._get_axis(a)) == 0 for a in self._AXIS_ORDERS)

Expand Down