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)

Performing Boolean selection

Indexes give us a very powerful and efficient means of looking up values in a Series based upon their labels. But what if you want to look up entries in a Series based upon the values?

To handle this scenario pandas provides us with Boolean selection. A Boolean selection applies a logical expression to the values of the Series and returns a new series of Boolean values representing the result of that expression upon each value. This result can then be used to extract only values where True was a result.

To demonstrate Boolean selection, let's start with the following Series and apply the greater than operator to determine values greater than or equal to 3:

This results in a Series with matching index labels and the result of the expression as applied to the value of each label. The dtype of the values is bool.

This series can then be used to...