读取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_)
标签:product,某列,classification,labels,label,order,csv,unordered,读取 来源: https://www.cnblogs.com/harbin-ho/p/14745948.html