pandas 的大小和数量有什么区别? [英] What is the difference between size and count in pandas?
本文介绍了 pandas 的大小和数量有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是熊猫中groupby("x").count
和groupby("x").size
之间的区别吗?
That is the difference between groupby("x").count
and groupby("x").size
in pandas ?
大小是否只排除nil?
Does size just exclude nil ?
推荐答案
count
不会:
size
includes NaN
values, count
does not:
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
这篇关于 pandas 的大小和数量有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文