df:
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 '-'
Code:
grp = df.groupby(df.class, axis=1).sum()
getting errors which I dont even understand. new to pandas, any suggestions would be great.
尝试这个:
print(sample.groupby('class').count())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.