我有这样一个系列:
13624 A
25257 D
15359 D
26226 D
10797 D
..
9733 D
25121 D
10143 C
1448 B
13627 B
Name: points, Length: 10189, dtype: object
我想应用sklearn.preprocessing
中的labelencoder()
函数并替换所有值。
le.fit_transform(y_train)
函数返回以下内容:
array([0, 3, 3, ..., 2, 1, 1])
这个数组是按原始索引排序的,所以想法是用这个数组正好替换值列。
我怎么能那么做?
您可以尝试创建具有相同索引的新系列,然后重新分配回:
y_train = pd.Series(le.fit_transform(y_train), index=y_train.index)