[英]Compare 2 values in Pandas Dataframe
Hi I have this dataframe嗨,我有这个数据框
and I am trying to compare which candy among 'Almond Joy'
and '3 Musketeers'
has the highest winpercent
(last column).我正在尝试比较'Almond Joy'
和'3 Musketeers'
哪种糖果的winpercent
最高(最后一栏)。
musketeers = candy_data.loc[candy_data.competitorname == '3 Musketeers']['winpercent']
almond = candy_data.loc[candy_data.competitorname == 'Almond Joy']['winpercent']
print(musketeers)
print("===========================")
print(almond)
if musketeers > almond:
more_popular = musketeers
else:
more_popular = almond
But I got this error.但我收到了这个错误。 Can someone tell me what is the problem here?有人能告诉我这里有什么问题吗?
Thank you.谢谢你。
You should get scalars, not series.你应该得到标量,而不是系列。
Try:尝试:
musketeers = candy_data.loc[candy_data.competitorname == '3 Musketeers']['winpercent'].mean()
almond = candy_data.loc[candy_data.competitorname == 'Almond Joy']['winpercent'].mean()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.