Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python LabelEncoder未将字符串转换为数字(0,1,2)_Python_Python 3.x_Machine Learning_Xgboost - Fatal编程技术网

Python LabelEncoder未将字符串转换为数字(0,1,2)

Python LabelEncoder未将字符串转换为数字(0,1,2),python,python-3.x,machine-learning,xgboost,Python,Python 3.x,Machine Learning,Xgboost,我有如下数据,我需要对变量进行编码,但LabelEncoder没有对字符串进行编码 我的数据如下所示 Delivery_class First Class Same Day Second Class Standard Class X=filtered_df.iloc[:, 1] labelencoder_X = LabelEncoder() X.values[:,1] = labelencoder_X.fit_transform(X.values[:,1].astype(str)) 即使在运

我有如下数据,我需要对变量进行编码,但LabelEncoder没有对字符串进行编码

我的数据如下所示

Delivery_class
First Class
Same Day
Second Class
Standard Class

X=filtered_df.iloc[:, 1]
labelencoder_X = LabelEncoder()
X.values[:,1] = labelencoder_X.fit_transform(X.values[:,1].astype(str))
即使在运行abovr代码之后,字符串仍然保持不变


请注意,我是XGBoost的初学者

不要重新分配给
X.values
。使用
X.iloc

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
X.iloc[:, 1] = le.fit_transform(X.values[:, 1].astype(str))
输出:

   Index  Ship_Mode
0      0          0
1      1          0
2      2          1
3      3          1
4      4          0
5      5          2

什么是
X.values[:,1].astype(str)
?你能提供打印(X)的结果吗?@Chris,附上X的截图