GROUP BY SUM on pandas数据框

时间:2016-04-16 18:21:26

标签: python python-3.x pandas

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()

得到我甚至不理解的错误。对熊猫来说,任何建议都会很棒。

1 个答案:

答案 0 :(得分:1)

试试这个:

print(sample.groupby('class').count())