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).
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.
CodePudding user response:
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()