【发布时间】:2019-08-22 07:30:46
【问题描述】:
过滤我的结果数据框时出现问题。我的数据集中有一个名为 PaymentAmount 的列,其中包含数字数据并希望执行操作以分配值
- 1 如果
data['PaymentAmount'] > 25000和 - 0 如果
data['PaymentAmount'] <= 25000
我尝试使用下面的
1 if data['PaymentAmount'] >= 25000 else 0
但出现以下错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-176-e368653724d0> in <module>
----> 1 1 if data['PaymentAmount'] >= 25000 else 0
~\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\core\generic.py in __nonzero__(self)
1574 raise ValueError("The truth value of a {0} is ambiguous. "
1575 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1576 .format(self.__class__.__name__))
1577
1578 __bool__ = __nonzero__
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
【问题讨论】:
标签: python pandas dataframe filtering