Skip to content

Commit 59da0f9

Browse files
committed
Address feedback to include examples of empty and non-empty with NaNs
1 parent f9ef74a commit 59da0f9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pandas/core/generic.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -847,16 +847,30 @@ def empty(self):
847847
848848
Notes
849849
-----
850-
If NDFrame contains only NaNs, it is still not considered empty.
850+
If NDFrame contains only NaNs, it is still not considered empty. See
851+
the example below.
851852
852853
Examples
853854
--------
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:
854867
855-
>>> # containing only NaNs does not make the df empty
856868
>>> df = pd.DataFrame({'A' : [np.nan]})
869+
>>> df
870+
A
871+
0 NaN
857872
>>> df.empty
858873
False
859-
>>> # if we drop NAs, the axes are now of length 0
860874
>>> df.dropna().empty
861875
True
862876

0 commit comments

Comments
 (0)