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)

Filtering groups from aggregation

Groups of data can be selectively dropped from processing using .filter(). This method is supplied a function that can be used to make group-level decisions on whether the entire group is included in the result after the combination. The function should return True if the group is to be included in the result and False to exclude it.

We will examine several scenarios using the following data:

The first demonstration will drop groups that do not have a minimum number of items. Specifically, they will be dropped if they only have one item or less:

The following example will omit groups that have any NaN values:

The next example will only select groups that have a mean that is greater than 2.0, the mean of the entire data set (basically, this selects groups of data that have an exceptional behavior as compared to the whole):

...