I'd like to know if a DataFrame I'm modifying is empty yet. The obvious way would be to compute its length. But that requires counting every row, which is extremely inefficient. Is there a more elegant way?
You can use the attribute df.empty
to check whether it's empty or not:
if df.empty:
print('DataFrame is empty!')
else:
print('DataFrame is not empty.')