December 2018
Beginner to intermediate
682 pages
18h 1m
English
Boolean indexing may be accomplished with both the .iloc and .loc indexers with the caveat that .iloc cannot be passed a Series but the underlying ndarray. Let's take a look at the one-dimensional ndarray underlying the criteria Series:
>>> a = criteria.values>>> a[:5]array([False, False, False, False, False], dtype=bool)>>> len(a), len(criteria)(4916, 4916)
The array is the same length as the Series, which is the same length as the movie DataFrame. The integer location for the boolean array aligns with the integer location of the DataFrame and the filter happens as expected. These arrays also work with the .loc operator as well but they are a necessity for .iloc.
Steps 6 and 7 show how to filter by columns instead of by rows. ...