DF:
a b class
0 0 +
0 1 +
1 0 -
预期产出:
group each column based on class value and find the count,
as in taking column 'a' as example the count should be 2
for class '+' and 1 for class '-'
代码:
grp = df.groupby(df.class, axis=1).sum()
得到我甚至不理解的错误。对熊猫来说,任何建议都会很棒。
答案 0 :(得分:1)
试试这个:
print(sample.groupby('class').count())