簡體   English   中英

按熊貓分組數據框總和

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM