pyspark.sql.DataFrame.isEmpty

DataFrame.isEmpty() → bool[source]

Checks if the DataFrame is empty and returns a boolean value.

New in version 3.3.0.

Changed in version 3.4.0: Supports Spark Connect.

Returns
bool

Returns True if the DataFrame is empty, False otherwise.

See also

DataFrame.count

Counts the number of rows in DataFrame.

Notes

  • Unlike count(), this method does not trigger any computation.

  • An empty DataFrame has no rows. It may have columns, but no data.

Examples

Example 1: Checking if an empty DataFrame is empty

>>> df_empty = spark.createDataFrame([], 'a STRING')
>>> df_empty.isEmpty()
True

Example 2: Checking if a non-empty DataFrame is empty

>>> df_non_empty = spark.createDataFrame(["a"], 'STRING')
>>> df_non_empty.isEmpty()
False

Example 3: Checking if a DataFrame with null values is empty

>>> df_nulls = spark.createDataFrame([(None, None)], 'a STRING, b INT')
>>> df_nulls.isEmpty()
False

Example 4: Checking if a DataFrame with no rows but with columns is empty

>>> df_no_rows = spark.createDataFrame([], 'id INT, value STRING')
>>> df_no_rows.isEmpty()
True