python - Python .loc 返回一个 TypeError
问题描述
我是使用 .loc 的新手,但每次我尝试使用它时,它都会返回“TypeError: 'DataFrame' object is not callable”。
例如,我无法让这个简单的代码(用于 pokemon API)工作:
print(df.loc(df('Attack') > 175))
TypeError: 'DataFrame' object is not callable
请有人帮忙,它真的让我烦恼为什么它不起作用?!?
解决方案
索引(iloc
和访问 column Attack
)应该用方括号完成,而不是圆括号(因为它们不是函数)
例如
df.loc[df['Attack'] > 175]
使用df('Attack')
,您正在尝试调用df
对象,这当然不是函数,因此不可调用
推荐阅读
- .net - UnitTests Visual Studio 中的 ServiceManager 实现
- gem5 - 研究 Gem5 CPU 模型的最佳方法是什么
- javascript - 求和嵌套数组
- android - Gradle 忽略 google maven 存储库,仅在 jcenter 上搜索
- python - 错误:在 Tensorflow1.x 中输入占位符时,无法识别张量,有什么建议吗?
- c++ - 如何使用 RAII 包装 C 分配返回错误代码
- php - 如果 print_r 在 PHP 中为空条件
- multithreading - 理解和分析多线程代码的最佳方法是什么?
- reactjs - 基于状态变化的组件条件渲染
- python - 从python代码执行字节码.pyc?