O'Reilly logo

Learning pandas by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Size, shape, uniqueness, and counts of values

The number of items in a Series object can be determined by several techniques. To demonstrate this, we will use the following Series:

In [16]:
   # example series, which also contains a NaN
   s = pd.Series([0, 1, 1, 2, 3, 4, 5, 6, 7, np.nan])
   s

Out[16]:
   0     0
   1     1
   2     1
   3     2
   4     3
   5     4
   6     5
   7     6
   8     7
   9   NaN
   dtype: float64

The length can be determined using the len() function:

In [17]:
   # length of the Series
   len(s)

Out[17]:
   10

Alternately, the length can be determined using the .size property:

In [18]:
   # .size is also the # of items in the Series
   s.size

Out[18]:
   10

The .shape property returns a tuple where the first item is the number of items:

In [19]:
   # .shape is a tuple with one value
 s.shape ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required