我从比尔啤酒数据中得到了啤酒评论示例,我已经运行了数百次。然而,在最近升级到Py3.6和最新的Numpy后,我收到了一个错误:T ypeError:'>' ' str'的实例之间不支持并且'浮动' 我以前没有见过,也不知道如何调试。我的代码如下,以及完全错误。
def get_beer_reviews(beer, common_users):
mask = (df.review_profilename.isin(common_users)) &
(df.beer_name==beer)
reviews = df[mask].sort_values('review_profilename')
reviews = reviews[reviews.review_profilename.duplicated()==False]
return reviews
beer_1_reviews = get_beer_reviews(beer_1, common_reviewers)
beer_2_reviews = get_beer_reviews(beer_2, common_reviewers)
cols = ['beer_name', 'review_profilename', 'review_overall',
'review_aroma', 'review_palate', 'review_taste']
beer_2_reviews[cols].head()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-15-8b20c3601bd3> in <module>()
4 reviews = reviews[reviews.review_profilename.duplicated()==False]
5 return reviews
----> 6 beer_1_reviews = get_beer_reviews(beer_1, common_reviewers)
7 beer_2_reviews = get_beer_reviews(beer_2, common_reviewers)
8
<ipython-input-15-8b20c3601bd3> in get_beer_reviews(beer, common_users)
1 def get_beer_reviews(beer, common_users):
----> 2 mask = (df.review_profilename.isin(common_users)) & (df.beer_name==beer)
3 reviews = df[mask].sort_values('review_profilename')
4 reviews = reviews[reviews.review_profilename.duplicated()==False]
5 return reviews
/Users/mpgartland/anaconda/lib/python3.6/site-packages/pandas/core/series.py in isin(self, values)
2553
2554 """
-> 2555 result = algorithms.isin(_values_from_object(self), values)
2556 return self._constructor(result, index=self.index).__finalize__(self)
2557
/Users/mpgartland/anaconda/lib/python3.6/site-packages/pandas/core/algorithms.py in isin(comps, values)
419 comps = comps.astype(object)
420
--> 421 return f(comps, values)
422
423
/Users/mpgartland/anaconda/lib/python3.6/site-packages/pandas/core/algorithms.py in <lambda>(x, y)
399 f = lambda x, y: htable.ismember_object(x, values)
400 if (_np_version_under1p8 and compat.PY3) or len(comps) > 1000000:
--> 401 f = lambda x, y: np.in1d(x, y)
402 elif is_integer_dtype(comps):
403 try:
/Users/mpgartland/anaconda/lib/python3.6/site-packages/numpy/lib/arraysetops.py in in1d(ar1, ar2, assume_unique, invert)
398 # Otherwise use sorting
399 if not assume_unique:
--> 400 ar1, rev_idx = np.unique(ar1, return_inverse=True)
401 ar2 = np.unique(ar2)
402
/Users/mpgartland/anaconda/lib/python3.6/site-packages/numpy/lib/arraysetops.py in unique(ar, return_index, return_inverse, return_counts)
209
210 if optional_indices:
--> 211 perm = ar.argsort(kind='mergesort' if return_index else 'quicksort')
212 aux = ar[perm]
213 else:
TypeError: '>' not supported between instances of 'str' and 'float'