Indicator whether Series/DataFrame is empty. True if Series/DataFrame is entirely empty (no items), meaning any of the axes are of length 0. Returns ------- bool If Series/DataFrame is empty, return True, if not return False. Se
(self)
| 1947 | |
| 1948 | @property |
| 1949 | def empty(self) -> bool: |
| 1950 | """ |
| 1951 | Indicator whether Series/DataFrame is empty. |
| 1952 | |
| 1953 | True if Series/DataFrame is entirely empty (no items), meaning any of the |
| 1954 | axes are of length 0. |
| 1955 | |
| 1956 | Returns |
| 1957 | ------- |
| 1958 | bool |
| 1959 | If Series/DataFrame is empty, return True, if not return False. |
| 1960 | |
| 1961 | See Also |
| 1962 | -------- |
| 1963 | Series.dropna : Return series without null values. |
| 1964 | DataFrame.dropna : Return DataFrame with labels on given axis omitted |
| 1965 | where (all or any) data are missing. |
| 1966 | |
| 1967 | Notes |
| 1968 | ----- |
| 1969 | If Series/DataFrame contains only NaNs, it is still not considered empty. See |
| 1970 | the example below. |
| 1971 | |
| 1972 | Examples |
| 1973 | -------- |
| 1974 | An example of an actual empty DataFrame. Notice the index is empty: |
| 1975 | |
| 1976 | >>> df_empty = pd.DataFrame({"A": []}) |
| 1977 | >>> df_empty |
| 1978 | Empty DataFrame |
| 1979 | Columns: [A] |
| 1980 | Index: [] |
| 1981 | >>> df_empty.empty |
| 1982 | True |
| 1983 | |
| 1984 | If we only have NaNs in our DataFrame, it is not considered empty! We |
| 1985 | will need to drop the NaNs to make the DataFrame empty: |
| 1986 | |
| 1987 | >>> df = pd.DataFrame({"A": [np.nan]}) |
| 1988 | >>> df |
| 1989 | A |
| 1990 | 0 NaN |
| 1991 | >>> df.empty |
| 1992 | False |
| 1993 | >>> df.dropna().empty |
| 1994 | True |
| 1995 | |
| 1996 | >>> ser_empty = pd.Series({"A": []}) |
| 1997 | >>> ser_empty |
| 1998 | A [] |
| 1999 | dtype: object |
| 2000 | >>> ser_empty.empty |
| 2001 | False |
| 2002 | >>> ser_empty = pd.Series() |
| 2003 | >>> ser_empty.empty |
| 2004 | True |
| 2005 | """ |
| 2006 | return any(len(self._get_axis(a)) == 0 for a in self._AXIS_ORDERS) |