groupby("x").count和groupby("x").sizepandas和之间的区别是什么?
groupby("x").count
groupby("x").size
大小是否仅排除nil?
size包含NaN值,count:
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)}) df Out[46]: a b c 0 0 1 1.067627 1 0 2 0.554691 2 1 3 0.458084 3 2 4 0.426635 4 2 NaN -2.238091 5 2 4 1.256943 In [48]: print(df.groupby(['a'])['b'].count()) print(df.groupby(['a'])['b'].size()) a 0 2 1 1 2 2 Name: b, dtype: int64 a 0 2 1 1 2 3 dtype: int64