Почему я получаю эту ошибку при сравнении двух Numpy массивов? - PullRequest
0 голосов
/ 21 января 2020

См. Ниже сообщение об ошибке. Он указывает на этот код, который принимает два массива numpy с брендами компании и проверяет, есть ли какие-либо новые названия брендов в столбце бренда new_df.

Я посмотрел на входные переменные new_df['brand'].unique(),existing_df['brand'].unique() и ни одна из них не равна None, они numpy массивы, поэтому я не понимаю, в чем проблема:

#find new brands 
brand_diff = np.setdiff1d(new_df['brand'].unique(),existing_df['brand'].unique(),False)
count_brand_diff = len(brand_diff)

TypeError                                 Traceback (most recent call last)
<ipython-input-75-254b4c01e085> in <module>
     71 
     72         #find new brands
---> 73         brand_diff = np.setdiff1d(new_df['brand'].unique(),existing_df['brand'].unique(),False)
     74         count_brand_diff = len(brand_diff)
     75 

<__array_function__ internals> in setdiff1d(*args, **kwargs)

~/opt/anaconda3/lib/python3.7/site-packages/numpy/lib/arraysetops.py in setdiff1d(ar1, ar2, assume_unique)
    782         ar1 = np.asarray(ar1).ravel()
    783     else:
--> 784         ar1 = unique(ar1)
    785         ar2 = unique(ar2)
    786     return ar1[in1d(ar1, ar2, assume_unique=True, invert=True)]

<__array_function__ internals> in unique(*args, **kwargs)

~/opt/anaconda3/lib/python3.7/site-packages/numpy/lib/arraysetops.py in unique(ar, return_index, return_inverse, return_counts, axis)
    260     ar = np.asanyarray(ar)
    261     if axis is None:
--> 262         ret = _unique1d(ar, return_index, return_inverse, return_counts)
    263         return _unpack_tuple(ret)
    264 

~/opt/anaconda3/lib/python3.7/site-packages/numpy/lib/arraysetops.py in _unique1d(ar, return_index, return_inverse, return_counts)
    308         aux = ar[perm]
    309     else:
--> 310         ar.sort()
    311         aux = ar
    312     mask = np.empty(aux.shape, dtype=np.bool_)

TypeError: '<' not supported between instances of 'NoneType' and 'NavigableString'```

1 Ответ

1 голос
/ 21 января 2020

Проблема с данными, которые вы используете, потому что код правильный,

пример:

>>existing_df
   brand
   apple
   apple 
   bmw

>>new_df
   brand
   apple
   lexus 
   bmw

>>count_brand_diff
    1

Следовательно, если вам нужна дополнительная помощь, приведите пример данных вы используете.

...