Skip to content

Commit e1cec52

Browse files
masongallojreback
authored andcommitted
DOC: Add examples and notes to empty documentation
closes pandas-dev#12393 Author: MasonGallo <[email protected]> Closes pandas-dev#12442 from MasonGallo/empty-clarity and squashes the following commits: 30f09ea [MasonGallo] Add see also section and replace i.e. with meaning 59da0f9 [MasonGallo] Address feedback to include examples of empty and non-empty with NaNs f9ef74a [MasonGallo] Change any to all 7abd759 [MasonGallo] Add examples and notes to empty documentation
1 parent d991a93 commit e1cec52

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

pandas/core/generic.py

+37-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,43 @@ def __contains__(self, key):
842842

843843
@property
844844
def empty(self):
845-
"""True if NDFrame is entirely empty [no items]"""
845+
"""True if NDFrame is entirely empty [no items], meaning any of the
846+
axes are of length 0.
847+
848+
Notes
849+
-----
850+
If NDFrame contains only NaNs, it is still not considered empty. See
851+
the example below.
852+
853+
Examples
854+
--------
855+
An example of an actual empty DataFrame. Notice the index is empty:
856+
857+
>>> df_empty = pd.DataFrame({'A' : []})
858+
>>> df_empty
859+
Empty DataFrame
860+
Columns: [A]
861+
Index: []
862+
>>> df_empty.empty
863+
True
864+
865+
If we only have NaNs in our DataFrame, it is not considered empty! We
866+
will need to drop the NaNs to make the DataFrame empty:
867+
868+
>>> df = pd.DataFrame({'A' : [np.nan]})
869+
>>> df
870+
A
871+
0 NaN
872+
>>> df.empty
873+
False
874+
>>> df.dropna().empty
875+
True
876+
877+
See also
878+
--------
879+
pandas.Series.dropna
880+
pandas.DataFrame.dropna
881+
"""
846882
return not all(len(self._get_axis(a)) > 0 for a in self._AXIS_ORDERS)
847883

848884
def __nonzero__(self):

0 commit comments

Comments
 (0)