python-3.x - Pandas DataFrame.empty() 给出 TypeError : 'bool' object is not callable

标签 python-3.x pandas

我的 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/

相关文章:

Python 参数在打印时返回 "<class ' tkinter.StringVar'>"

python - 在python中合并多个表后更改重复的列名

Python Pandas 基于列相乘并添加后缀

python - Pandas 交叉表百分比

python - 对数据框中所有行组合求和的更快方法

具有产生 NameError 的函数链的 Python exec

python - 如何使用python中的map将分类(由字母和数字组成)转换为数字?

python - 条件列创建 DF Pandas

python - 处理 ZeroDivisionError 的最佳方法?

python - 如何将 Tableau .hyper 文件转换为 Pandas 数据帧?