2015-01-05 106 views

回答

2
df 
    A  B   C   D 
0 foo one 0.075964 2.132502 
1 bar one -1.061731 0.025212 
2 foo two 0.753592 0.031765 
3 bar three 0.379773 0.996792 
4 foo two 0.297801 1.059324 
5 bar two -1.400107 -0.651873 
6 foo one -1.084224 0.243731 
7 foo three -3.181693 -0.413512 

g = df.groupby(['A', 'B']) 

選項1
ngroups

g.ngroups 
6 

選項2
len

len(g) 
6 

如果你想找到的每個組的大小,你可以使用dfGroupBy.size

g.size() 
A B  
bar one  1 
    three 1 
    two  1 
foo one  2 
    three 1 
    two  2 
dtype: int64 
相關問題