我的 DataFrame 管道需要处理空的和格式错误的结果,我添加了一个测试 df.empty()
并遇到此错误:
(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)
很明显,这个示例 DF 将返回
False
,因为它不是空的(我只测试一行)但现在我很好奇为什么我收到这个错误它不是 bool
.
最佳答案
pandas.DataFrame.empty
不是一个可调用的方法,而是一个属性。
只需将其用作 tabledf.empty
而不是 tabledf.empty()
您遇到的错误是由于您所做的类似于:
>>> 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
关于python-3.x - Pandas DataFrame.empty() 给出 TypeError : 'bool' object is not callable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57734449/