如题目:
将类别重新编码为 0,1,2,即将列'class'不同元素重新编码,即 Iris-setosa 编码为 0,Iris-versicolor 编码为 1,Iris-versicolor 编码为 2;
代码:
df = pd.read_csv(file, names = names) dic = {'Iris-setosa':0,'Iris-versicolor':1,'Iris-virginica':2} df['class'] = df['class'].replace((dic))