我有一个Pandas数据框架,其中有一列标题为"label"
。它有三列,分别标题为featureA_1, featureA_2, featureA_3
。这些列表示表示featureA
的一个热编码值(可以有三个唯一值)的列。同样,它也有两个列,分别名为featureB_1
和featureB_2
。这些列表示featureB
的一个热编码值(可以有两个不同的值)
下面是所述数据帧的示例
可以使用以下方法生成上述数据帧:
import pandas as pd
dictt = {
"label": ["cat", "cat", "cat", "cat", "cat", "dog", "dog", "dog"],
"featureA_1": [1, 0, 1, 1, 0, 1, 1, 0],
"featureA_2": [0, 1, 0, 0, 0, 0, 0, 0],
"featureA_3": [0, 0, 0, 0, 1, 0, 0, 1],
"featureB_1": [0, 0, 1, 1, 0, 0, 1, 1],
"featureB_2": [1, 1, 0, 0, 1, 1, 0, 0],
}
df1 = pd.DataFrame(dictt)
由于一个热编码,上述数据帧中的每一行将只有一个特征值featureA_1, featureA_2, featureA_3
的值为1,其他的值为0。类似地,每一行对于特征值featureB_1
和featureB_2
中的一个只有值1,而对于另一个则为0
我想创建一个数据框,在该数据框中,每个标签中具有特征值featureA_1, featureA_2, featureA_3
的条目百分比以及每个标签中具有特征值featureB_1
和featureB_2
的条目百分比。
我还想得到FeatureUrea值类型和featureB值类型百分比的标准偏差。
以下是我希望拥有的数据帧示例:
这样做最有效的方法是什么?在我的实际工作中,我将拥有数百万行的数据帧
使用:
相关问题 更多 >
编程相关推荐