gpt4 book ai didi

python - 为什么我会收到 ValueError : The truth value of a Series is ambiguous. 使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()

转载 作者:太空宇宙 更新时间:2023-11-04 11:06:24 25 4
gpt4 key购买 nike

下面的代码给我值错误:

major_males=[]

for row in recent_grads:
if recent_grads['Men']>recent_grads['Women']:
major_males.append(recent_grads['Major'])
display(major_males)

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

最佳答案

那是因为您比较的是一个系列而不是一个值。我猜你的意图是 if row['Men'] > row['Women']

其次这样做会更有效率


major_males = recent_grads[recent_grads.Men > recent_grads.Women].Major.to_list()

关于python - 为什么我会收到 ValueError : The truth value of a Series is ambiguous. 使用 a.empty、a.bool()、a.item()、a.any() 或 a.all(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59350625/

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