Today, we're approaching data analysis from a new angle by applying filtering to grouped DataFrames. We will review DataFrame grouping and introduce filtering, illustrating these concepts with examples. By the end of this lesson, you will be equipped with the necessary skills to effectively group and filter data.
As a quick recap, pandas
is a highly influential Python module for data analysis, with powerful classes such as DataFrames at its core. DataFrames are data tables, and you can group the data within them using the groupby()
function. Here is an example of grouping data within a DataFrame by 'Product'
:
To filter grouped data, we will need functions. Let's recall how to easily create and use them.
In Python, lambda functions are small anonymous functions. They can take any number of arguments but only have one expression.
Consider a situation where we use a function to calculate the total price after adding the sales tax. In a place where the sales tax is 10%, the function to calculate the total cost could look like:
Regular Function
