What is the difference between size and count in pandas?

后端 未结 5 1834
误落风尘
误落风尘 2020-11-22 04:37

That is the difference between groupby(\"x\").count and groupby(\"x\").size in pandas ?

Does size just exclude nil ?

5条回答
  •  失恋的感觉
    2020-11-22 05:22

    Just to add a little bit to @Edchum's answer, even if the data has no NA values, the result of count() is more verbose, using the example before:

    grouped = df.groupby('a')
    grouped.count()
    Out[197]: 
       b  c
    a      
    0  2  2
    1  1  1
    2  2  3
    grouped.size()
    Out[198]: 
    a
    0    2
    1    1
    2    3
    dtype: int64
    

提交回复
热议问题