python-3.x - Pandas DataFrame.empty() 给出 TypeError: 'bool' object is not callable
问题描述
我的 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
推荐阅读
- mysql - 对多个条件进行 AND 运算时不可能 WHERE
- python-3.x - 如何使用 python 向 Skype 群聊发送自动消息
- bash - 仅替换嵌套在非数字旁边的字符串
- javascript - 数据表信息页脚显示两次
- json - python RegEx json 双引号
- c# - 如何将第三方分析仪添加到 sonarqube?
- c# - 如何使用 .net core 3.0 中开发的 wpf 中的 wcf
- powershell - PowerShell 从服务器获取用户、组
- c++ - DeleteIPAddress 功能有效,但会触发断开连接
- php - Dropzone.js 使用 php 上传不遵循