Pandas DataFrame empty
HOW TO CHECK IF THE DATAFRAME IS EMPTY OR NOT?
- Check if the DataFrame is empty or not by using the DataFrame.empty.
- It returns the Boolean value.
- If the DataFrame is empty, then it returns True.
- If the DataFrame is not empty, then it returns False.
CREATE A EMPTY DATAFRAME:
- Create an empty dataframe and will check if it is empty or not by using the property DataFrame.empty
- If it is empty, then it returns True.
import pandas as pd
empty_dataframe = pd.DataFrame()
if empty_dataframe.empty:
print('True')
empty_dataframe = pd.DataFrame()
if empty_dataframe.empty:
print('True')
- Create a non-empty dataframe and will check if the dataframe is empty or not.
- 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')
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
Post a Comment