Is there a way to check if both list and dataframe is empty? I am using df.count() == 0 but is there a more efficient way to check the data frame and the list is empty.
Asked
Active
Viewed 3,512 times
-1
-
Does this answer your question? [How to check whether a pandas DataFrame is empty?](https://stackoverflow.com/questions/19828822/how-to-check-whether-a-pandas-dataframe-is-empty) – Joe Ferndz Nov 25 '20 at 22:45
-
https://stackoverflow.com/questions/32707620/how-to-check-if-spark-dataframe-is-empty – Joe Ferndz Nov 25 '20 at 22:46
-
len(df.head(1)) > 0 or df.head(1).isEmpty or df.take(1).isEmpty – Joe Ferndz Nov 25 '20 at 22:47
1 Answers
0
Hope this helped you, using: df.empty
and not list
import pandas as pd
list = [1,2,3,4] #fulled list
df = pd.DataFrame(list) #fulled dataframe
print (df)
print(df.empty) #False
print(not list) #False
print("\n")
list = [] #empty list
df = pd.DataFrame(list) #empty dataframe
print (df)
print(df.empty) #True
print(not list) #True
[Result]:
0 0 1 1 2 2 3 3 4 False False Empty DataFrame Columns: [] Index: [] True True

AziMez
- 2,014
- 1
- 6
- 16