Getting values from a pandas series
A pandas series is a one-dimensional array-like structure that takes a NumPy data type. Each series also has an index; that is, an array of data labels. If an index is not specified when the series is created, it will be the default index of 0 through N-1.
There are several ways to create a pandas series, including from a list, dictionary, NumPy array, or a scalar. In our data cleaning work, we will most frequently be accessing data series that contain columns of data frames, using either attribute access (dataframename.columname
) or bracket notation (dataframename['columnname']
). Attribute access cannot be used to set values for series, but bracket notation will work for all series operations.
In this recipe, we'll explore several ways we can get values from a pandas series. These techniques are very similar to the methods we used to get rows from a pandas DataFrame, which we covered in the Selecting rows recipe of Chapter 3...