如何解决列未编码
我有一列名为“教育”的书。我正在尝试使用Label Encoder对其进行编码,但弹出以下错误
[我无法发布图片,因此数据的链接附在下面] [1]
TypeError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/sklearn/preprocessing/_label.py in _encode(values,uniques,encode,check_unknown)
112 try:
--> 113 res = _encode_python(values,encode)
114 except TypeError:
/opt/conda/lib/python3.7/site-packages/sklearn/preprocessing/_label.py in _encode_python(values,encode)
60 if uniques is None:
---> 61 uniques = sorted(set(values))
62 uniques = np.array(uniques,dtype=values.dtype)
TypeError: '<' not supported between instances of 'str' and 'float'
During handling of the above exception,another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-90-64573b8efccb> in <module>
----> 1 df_temp['education']=encoder1.fit_transform(df_temp['education'])
/opt/conda/lib/python3.7/site-packages/sklearn/preprocessing/_label.py in fit_transform(self,y)
254 """
255 y = column_or_1d(y,warn=True)
--> 256 self.classes_,y = _encode(y,encode=True)
257 return y
258
/opt/conda/lib/python3.7/site-packages/sklearn/preprocessing/_label.py in _encode(values,check_unknown)
115 types = sorted(t.__qualname__
116 for t in set(type(v) for v in values))
--> 117 raise TypeError("Encoders require their input to be uniformly "
118 f"strings or numbers. Got {types}")
119 return res
TypeError: Encoders require their input to be uniformly strings or numbers. Got ['float','str'] ```
[1]: https://i.stack.imgur.com/5F2uC.png
解决方法
您可以尝试
df_temp['education']=encoder1.fit_transform(df_temp['education'].astype(str))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。