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 ...
Get Learning pandas now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.