python - 在Python的列表中使用min函数获取AttributeError

标签 python list function error-handling min

源代码

data[data['current_balance'] == ['current_balance'].min()]
错误
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-17-7c38f54b69b2> in <module>
      1 #observation with minimum current balance
----> 2 data[data['current_balance'] == ['current_balance'].min()]

AttributeError: 'list' object has no attribute 'min'

最佳答案

您正在列表min()上使用['current_balance'],您的代码应如下所示:

data[data['current_balance'] == min(data['current_balance'])]
OR
data[data['current_balance'] == data['current_balance'].min()]
我不知道data['current_balance']是什么类型的对象。但是上述方法之一可以消除您遇到的错误。

EDIT here some link for further informations:


指南
  • w3schools.com | min function
  • geeksforgeeks.org | max() and min() in Python

  • 堆栈溢出
  • how does the python min function works
  • 关于python - 在Python的列表中使用min函数获取AttributeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65488498/

    相关文章:

    Python - 编辑 CSV 文件中的特定单元格

    python - 在列表中查找 numpy 数组的索引

    python - 使用 itertools 进行枚举条件仅获取某些列表索引(python)

    Python。 "zip"字符和列表的最佳方法

    java - 具有不同类型头的双向链表

    python - 平衡两个列表,直到它们的总和相等,并且在 Python 中的两个列表中交换最小

    c - 使用函数传递数组

    python - 如何删除 0 的转换 pandas 数据帧以记录

    C++函数返回没有某些字段的对象

    python - 如何绘制给定函数 f(x) 的基于文本的图形?