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, 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 by selecting columns of DataFrames, 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, Taking...