

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check whether a pandas DataFrame is empty?
Use the DataFrame.empty property to check if DataFrame contains the data or not (empty or not). The DataFrame.empty attribute returns a boolean value indicating whether this DataFrame is empty or not.
If the DataFrame is empty, it will return True. and it will return False If the DataFrame is not empty.
Example 1
In the following example, we have initialized a DataFrame with some data and then applied the empty attribute to check if the empty attribute returns False or not.
# importing pandas package import pandas as pd # create an empty DataFrame df = pd.DataFrame([['a','b','c'],['b','c','d'], ['d','e','f'],['f','g','h']], columns=['Col1','Col2','Col3']) print("DataFrame:") print(df) # Apply empty attribute to the DataFrame print('Output:') print(df.empty)
Output
The output is given below −
DataFrame: Col1 Col2 Col3 0 a b c 1 b c d 2 d e f 3 f g h Output: False
The attribute empty successfully returns the boolean value “False” as output for the given DataFrame.
Example 2
For this example, we will apply the empty attribute to the empty DataFrame, so that initially we have created an empty DataFrame using pandas DataFrame constructor.
# importing pandas package import pandas as pd # create an empty DataFrame df = pd.DataFrame() print("DataFrame:") print(df) # Apply empty attribute to the DataFrame print('Output:') print(df.empty)
Output
The output is given below −
DataFrame: Empty DataFrame Columns: [] Index: [] Output: True
The empty attribute generated the output for True the given DataFrame, it is a valid output Since the given dataframe is empty.
- Related Questions & Answers
- How to check whether an array is empty using PHP?
- C# program to check whether a list is empty or not
- Python program to check whether a list is empty or not?
- Check whether a Stack is empty or not in Java
- Check whether a HashSet is empty or not in Java
- Check whether a field is empty or null in MySQL?
- How to check if any value is NaN in a Pandas DataFrame?
- Python Pandas - Check if an interval is empty
- Check whether a NavigableMap empty or not in Java
- How to check the data type in pandas DataFrame?
- How to check if a C# list is empty?
- Check whether IdentityHashMap empty or not in Java?
- How to check whether the Pandas series is having Nan values or not?
- Python - Check if Pandas dataframe contains infinity
- How to check whether a JavaScript date is valid?