Examples of how to check if a pandas DataFrame is empty:
Table of contents
Create an empty dataframe
Let's create an empty dataframe with pandas
import pandas as pddf = pd.DataFrame()print(df)
gives
Empty DataFrameColumns: []Index: []
Check if dataframe is empty
To check if a dataframe is empty a solution is to use "empty":
df.empty
returns
True
here.
With a if statement:
if df.empty:print("Oups, your dataframe is empty !")
Another example
df = pd.DataFrame([1,2,3])print(df)
gives
00 11 22 3
and
df.empty
gives then
False
Related posts
| Links | Site |
|---|---|
| How to create an empty data frame with pandas and add new entries row by row ? | moonbooks.org |
| How to add an empty column to an existing dataframe with pandas ? | moonbooks.org |
