What is the difference between size and count in pandas?

后端 未结 5 1828
误落风尘
误落风尘 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:23

    In addition to all above answers, I would like to point out one more diffrence which I seem significant.

    You can correlate Panda's Datarame size and count with Java's Vectors size and length. When we create vector some predefined memory is allocated to it. when we reach closer to number of elements it can occupy while adding elements, more memory is allocated to it. Similarly, in DataFrame as we add elements, memory allocated to it increases.

    Size attribute gives number of memory cell allocated to DataFrame whereas count gives number of elements that are actually present in DataFrame. For example,

    You can see though there are 3 rows in DataFrame, its size is 6.

    This answer covers size and count difference with respect to DataFrame and not Pandas Series. I have not checked what happens with Series

提交回复
热议问题