2 The Series Object
This chapter covers:
- Instantiating Series objects from lists, dictionaries, and more
- Creating a custom index for a Series
- Accessing attributes and invoking methods on a Series
- Performing mathematical operations on a Series
- Passing the Series to Python's built-in functions
The Series is one of two primary data structures available in pandas. It is a one-dimensional labelled array for storing homogenous data. An array is simply an ordered collection of values, analogous to a Python list. The term "homogenous" means that the values are of the same data type.
Each Series value is assigned a label and an order in line. The label is an identifier for the value and can be of any data type. The order is represented by an integer; the first value occupies position 0. The data structure is one-dimensional because any element can be accessed by one reference point, either its label or its numeric position. The combination of labels or positions forms what's called the index of the Series.
A Series combines and expands upon the best features of Python’s native data structures. Like a list, a Series holds its values in a sequenced order. Like a dictionary, each value is accessed by a key or label.
Multidimensional pandas data structures like the DataFrame are composed of one or more Series objects joined together. As the fundamental building block of pandas, the Series represents the perfect starting point to begin our exploration of the library.