Selection and Assignment
In the previous chapter, we looked at how to create a pd.Series
and pd.DataFrame
, and we also looked at their relationship to the pd.Index
. With a foundation in constructors, we now shift focus to the crucial processes of selection and assignment. Selection, also referred to as indexing, is considered a getter; i.e., it is used to retrieve values from a pandas object. Assignment, by contrast, is a setter that is used to update values.
The recipes in this chapter start out by showing you how to retrieve values from pd.Series
and pd.DataFrame
objects, with ever-increasing complexity. We will eventually introduce the pd.MultiIndex
, which can be used to select data hierarchically, before finally ending with an introduction to the assignment operators. The pandas API takes great care to reuse many of the same methods for selection and assignment, which ultimately allows you to be very expressive in how you would like to interact with your data.
By the end...