gpt4 book ai didi

python - 是否存在运算符(operator)错误,因为执行后它说不明确错误。我在做什么错误?

转载 作者:行者123 更新时间:2023-12-02 04:41:31 24 4
gpt4 key购买 nike

elder_data.head()
Sex Name Fund Elder Rating Caretaker Rating
0 Female A'A NAYHIA 56154 3 3
1 Male AADHAV 31118 3 4
2 Female AADHYA 23523 3 2
3 Male AADIT 13202 2 2
4 Male AADITH 39505 2 4


if elder_data['Elder Rating'] >=3 | elder_data['Caretaker Rating'] >=3:
elder_data["Status"]="Approved"
else:
elder_data["Status"]="Not Approved"
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-31-646b023be552> in <module>
----> 1 if elder_data['Elder Rating'] >=3 | elder_data['Caretaker Rating'] >=3:
2 elder_data["Status"]="Approved"
3 else:
4 elder_data["Status"]="Not Approved"

~\Anaconda3\lib\site-packages\pandas\core\generic.py in __nonzero__(self)
1476 raise ValueError("The truth value of a {0} is ambiguous. "
1477 "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
-> 1478 .format(self.__class__.__name__))
1479
1480 __bool__ = __nonzero__

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

** 我想创建一个新的“状态”列,如果长者评级和看护者评级大于 3,则状态将获得批准

但是我收到一个错误。如何纠正?**

最佳答案

第一个问题是在链接条件中缺少(),因为使用了运算符优先级和设置新值 numpy.where :

elder_data["Status"] = np.where((elder_data['Elder Rating'] >=3) | 
(elder_data['Caretaker Rating'] >=3),
'Approved',
'Not Approved')

关于python - 是否存在运算符(operator)错误,因为执行后它说不明确错误。我在做什么错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59874267/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com