2 The Series object

 

This chapter covers

  • Instantiating Series objects from lists, dictionaries, tuples, and more
  • Setting a custom index on a Series
  • Accessing attributes and invoking methods on a Series
  • Performing mathematical operations on one or more Series
  • Passing the Series to Python’s built-in functions

One of pandas’ core data structures, the Series is a one-dimensional labeled array for homogeneous data. An array is an ordered collection of values comparable to a Python list. The term homogeneous means that the values are of the same data type (all integers or all Booleans, for example).

Pandas assigns each Series value a label—an identifier we can use to locate the value. The library also assigns each Series value an order—a position in line. The order starts counting from 0; the first Series value occupies position 0, the second value occupies position 1, and so on. The Series is a one-dimensional data structure because we need one reference point to access a value: either a label or a position.

A Series combines and expands the best features of Python’s native data structures. Like a list, it holds its values in a sequenced order. Like a dictionary, it assigns a key/label to each value. We gain the benefits of both of those objects plus more than 180 methods for data manipulation.

2.1 Overview of a Series

2.1.1 Classes and instances

2.1.2 Populating the Series with values

2.1.3 Customizing the Series index

2.1.4 Creating a Series with missing values

2.2 Creating a Series from Python objects

2.3 Series attributes

2.4 Retrieving the first and last rows

2.5 Mathematical operations

2.5.1 Statistical operations

2.5.2 Arithmetic operations

2.5.3 Broadcasting

2.6 Passing the Series to Python’s built-in functions

2.7 Coding challenge

2.7.1 Problems

2.7.2 Solutions

Summary