[英]GROUP BY SUM ON pandas data frame
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())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.