pandas数据批量标签编码

Published on Aug. 22, 2023, 12:11 p.m.

批量标签编码

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
for i in range(0,X.shape[1]):
if X.dtypes[i]=='object':
X[X.columns[i]] = le.fit_transform(X[X.columns[i]])

https://stackoverflow.com/questions/24458645/label-encoding-across-multiple-columns-in-scikit-learn

Tags: