Pandas DataFrame empty

HOW TO CHECK IF THE DATAFRAME IS EMPTY OR NOT?

  1. Check if the DataFrame is empty or not by using the DataFrame.empty
  2. It returns the Boolean value.
  3. If the DataFrame is empty, then it returns True.
  4. If the DataFrame is not empty, then it returns False.

CREATE A EMPTY DATAFRAME:

  1. Create an empty dataframe and will check if it is empty or not by using the property DataFrame.empty
  2. If it is empty, then it returns True.

import pandas as pd 

empty_dataframe = pd.DataFrame()

if empty_dataframe.empty:
    print('True')




CREATE A NON-EMPTY DATAFRAME:

  1. Create a non-empty dataframe and will check if the dataframe is empty or not. 
  2. If it is not empty, then it returns False.

import pandas as pd 

pd_dataframe= pd.DataFrame([['Vetri',20],['Vishal',21],['Jack',18]], columns=['Name', 'Age'])

if 
pd_dataframe.empty is False:
    print('False')





Thanks for choosing our blog 😊. 




Comments

Popular posts from this blog

MySQL Tutorial Part 1

Introduction to Java