读取csv中某列转为数字,顺序不变
实际情况是:在读取文件中的“类别”信息,将类别信息转为id,且顺序按照原来的数据顺序排序
labels = list(data['product_classification']) unordered = set(labels) print("unorderd_class: ",unordered) order = sorted(unordered, key=labels.index) print("ordered_class: ", order) label_ = dict(zip(order, range(len(order)))) labels_true = data["product_classification"].map(label_)