在熊猫数据框上按总和分组

安基·贾恩(Ankit Jain)

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

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

塔诺斯

试试这个:

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章