I am trying to define a function then apply the function to the dataframe called reviews.
def stars(country, points):
if country == 'Canada':
return 3
elif points >= 95:
return 3
elif points >= 85:
return 2
else:
return 1
star_ratings = reviews.apply(lambda x: stars(x['points'], x['country']), axis=1)
I get the error:
<ipython-input-46-42befd5aa1a8> in stars(country, points)
2 if country == 'Canada':
3 return 3
----> 4 elif points >= 95:
5 return 3
6 elif points >= 85:
TypeError: '>=' not supported between instances of 'str' and 'int'
How should I rectify the code to make it work? Also, is the use of lambda here correct/common practice? Thanks!