我正在此处对数据实施一种热编码
Version Cluster_Size Hardware_type
1.0.4 3 Aplha,Alpha,Aplha
1.0.2 3 Aplha,Beta,Aplha
1.0.9 3 Aplha,Beta,Gama
在df ['hardware_type']。str.get_dummies(sep =',')之后,我能够获得这样的数据帧
Version Cluster_Size Hardware_type Alpha Beta Gama
1.0.4 3 Alpha,Alpha,Alpha 1 0 0
1.0.2 3 Alpha,Beta,Alpha 1 1 0
1.0.9 3 Alpha,Beta,Gama 1 1 1
这正是一键编码应做的事情,但我正在尝试实现类似的方法,其中我可以获取在各自单元格中出现的类别值的计数。
Version Cluster_Size Hardware_type Alpha Beta Gama
1.0.4 3 Alpha,Alpha,Alpha 3 0 0
1.0.2 3 Alpha,Beta,Alpha 2 1 0
1.0.9 3 Alpha,Beta,Gama 1 1 1
有没有办法做这样的事情?谢谢您的时间。
如果使用Series.str.get_dummies
,则没有有关计数的信息。