Book Image

Learning Pandas

By : Michael Heydt
Book Image

Learning Pandas

By: Michael Heydt

Overview of this book

Table of Contents (19 chapters)
Learning pandas
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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

Out[19]:
   (10,)

The number of the values that are not part of the NaN can be found by using the .count() method:

In [20]:
   # count() returns the number of non...