为什么会出现ValueError:系列的真值不明确.使用a.empty,a.bool(),a.item(),a.any()或a.all() [英] Why am I getting ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
本文介绍了为什么会出现ValueError:系列的真值不明确.使用a.empty,a.bool(),a.item(),a.any()或a.all()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码为我提供了值错误:
The following code gives me Value Error:
major_males=[]
for row in recent_grads:
if recent_grads['Men']>recent_grads['Women']:
major_males.append(recent_grads['Major'])
display(major_males)
ValueError:系列的真值不明确.使用a.empty,a.bool(),a.item(),a.any()或a.all()
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
推荐答案
如果 recent_grads
是一个数据帧,那么这就是您的for循环的样子
If recent_grads
is a dataframe, then this is how your for loop would look like
major_males=[]
for i, row in recent_grads.iterrows():
if row['Men']>row['Women']:
major_males.append(row['Major'])
display(major_males)
这篇关于为什么会出现ValueError:系列的真值不明确.使用a.empty,a.bool(),a.item(),a.any()或a.all()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文