ankit jain ankit jain - 2 years ago 175
Python Question

GROUP BY SUM ON pandas data frame


a b class
0 0 +
0 1 +
1 0 -

expected output:

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

getting errors which I dont even understand. new to pandas, any suggestions would be great.

Answer Source

Try this:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download