My DataFrame pipeline needs to handle empty and malformed results, and I added a test df.empty()
and encountered this error:
(Pdb) isinstance(tabledf, pd.DataFrame)
True
(Pdb) tabledf.empty()
*** TypeError: 'bool' object is not callable
(Pdb) tabledf
From Location Account Description Value TableName
0 NaN NaN nan TOTAL 0 countreport
(Pdb) tabledf.shape
(1, 6)
Clearly this example DF would return False
, because it's not empty (I'll just test for only one row) but now I'm curious why I'm getting this error its not a bool
.
pandas.DataFrame.empty
is not a callable method, but a property.
Just use it as tabledf.empty
rather than tabledf.empty()
The error you are getting is due to the fact that what you are doing is akin to:
>>> some_boolean = True
>>> some_boolean()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-13-02ece9c024ce> in <module>
1 boolean = False
----> 2 boolean()
TypeError: 'bool' object is not callable
empty
is an attriibute, not a method, s remove the ()
df = pd.DataFrame()
print(df.empty)
# True
df=pd.DataFrame({"a": [1]})
print(df.empty)
# False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With