即使處理了缺失值,我也面臨着多個變量的這個錯誤。 例如:LabelEncoder:TypeError:'>'不支持'float'和'str'的實例
le = preprocessing.LabelEncoder()
categorical = list(df.select_dtypes(include=['object']).columns.values)
for cat in categorical:
print(cat)
df[cat].fillna('UNK', inplace=True)
df[cat] = le.fit_transform(df[cat])
# print(le.classes_)
# print(le.transform(le.classes_))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-24-424a0952f9d0> in <module>()
4 print(cat)
5 df[cat].fillna('UNK', inplace=True)
----> 6 df[cat] = le.fit_transform(df[cat].fillna('UNK'))
7 # print(le.classes_)
8 # print(le.transform(le.classes_))
C:\Users\paula.ceccon.ribeiro\AppData\Local\Continuum\Anaconda3\lib\site-packages\sklearn\preprocessing\label.py in fit_transform(self, y)
129 y = column_or_1d(y, warn=True)
130 _check_numpy_unicode_bug(y)
--> 131 self.classes_, y = np.unique(y, return_inverse=True)
132 return y
133
C:\Users\paula.ceccon.ribeiro\AppData\Local\Continuum\Anaconda3\lib\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 'float' and 'str'
檢查,導致錯誤結果插件變量:
df['CRM do Médico'].isnull().sum()
0
此外NaN值,這可能是造成這個錯誤?
請張貼錯誤堆棧跟蹤。 – MarkWeston
完成,@MarkWeston。 – pceccon