江户川乱折腾
size包括NaN价值,count不:In [46]:df = pd.DataFrame({'a':[0,0,1,2,2,2], 'b':[1,2,3,4,np.NaN,4], 'c':np.random.randn(6)})dfOut[46]:
a b c0 0 1 1.0676271 0 2 0.5546912 1 3 0.4580843 2 4 0.4266354 2 NaN -2.2380915 2 4 1.256943In [48]:print(df.groupby(['a'])['b'].count())print(df.groupby(['a'])['b'].size())a0 21 12 2Name: b, dtype: int64
a0 21 12 3dtype: int64