chapter two

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.

2.1       Overview of a Series

2.1.1   Modules, Classes, and Instances

2.1.2   Populating the Series with Values

2.1.3   Customizing the Index

2.1.4   Creating a Series with Missing Values

2.2       Create a Series from Python Objects

2.2.1   Dictionaries

2.2.2   Tuples

2.2.3   Sets

2.2.4   NumPy Arrays

2.3       Retrieving the First and Last Rows

2.4       Mathematical Operations

2.4.1   Arithmetic Operations

2.4.2   Broadcasting

2.5       Passing the Series to Python's Built-In Functions

2.6       Coding Challenges / Exercises

2.7       Summary