【发布时间】:2021-02-16 09:05:32
【问题描述】:
我想从分类数据创建即时编码数据,您可以在此处查看。
Label1 Label2 Label3
0 Street fashion Clothing Fashion
1 Clothing Outerwear Jeans
2 Architecture Property Clothing
3 Clothing Black Footwear
4 White Photograph Beauty
问题(对我来说)是一个特定的标签(例如服装)可以在标签 1、标签 2 或标签 3 中。我试过 pd.get_dummies 但这会创建如下数据:
Label1_Clothing Label2_Clothing Label3_Clothing
0 0 1 0
1 1 0 0
2 0 0 1
有没有办法让每个标签只有一个虚拟变量列?而是:
Label_Clothing Label_Street Fashion Label_Architecture
0 1 1 0
1 1 0 0
2 1 0 1
我是编程新手,很高兴得到您的帮助。
最好, 贝尔纳多
【问题讨论】:
标签: python pandas machine-learning one-hot-encoding dummy-variable