Book Image

Learning pandas - Second Edition

By : Michael Heydt
Book Image

Learning pandas - Second Edition

By: Michael Heydt

Overview of this book

You will learn how to use pandas to perform data analysis in Python. You will start with an overview of data analysis and iteratively progress from modeling data, to accessing data from remote sources, performing numeric and statistical analysis, through indexing and performing aggregate analysis, and finally to visualizing statistical data and applying pandas to finance. With the knowledge you gain from this book, you will quickly learn pandas and how it can empower you in the exciting world of data manipulation, analysis and science.
Table of Contents (16 chapters)

Slicing a Series into subsets

pandas Series support a feature called slicing. Slicing is a powerful way to retrieve subsets of data from a pandas object. Through slicing, we can select data based upon position or index labels and have greater control over the sequencing of the items that result (forwards or reverse) and the interval (every item, every other).

Slicing overloads the normal array [] operator (and also .loc[], .iloc[], and .ix[]) to accept a slice object. A slice object is created using a syntax of start:end:step, the components representing the first item, last item, and the increment between each item that you would like as the step.

Each component of the slice is optional and provides a convenient means to select entire rows by omitting a component of the slice specifier.

To start demonstrating slicing, we will use the following Series:

We can select consecutive...