未编码的列
Column not being encoded
我有一个名为“教育”的专栏。我正在尝试使用标签编码器对其进行编码,但弹出以下错误
[我无法 post 图片,所以 link 数据附在下面][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, uniques, encode)
114 except TypeError:
/opt/conda/lib/python3.7/site-packages/sklearn/preprocessing/_label.py in _encode_python(values, uniques, 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, uniques, encode, 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))
我有一个名为“教育”的专栏。我正在尝试使用标签编码器对其进行编码,但弹出以下错误
[我无法 post 图片,所以 link 数据附在下面][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, uniques, encode)
114 except TypeError:
/opt/conda/lib/python3.7/site-packages/sklearn/preprocessing/_label.py in _encode_python(values, uniques, 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, uniques, encode, 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))