Session Ready
Exercise

Grouping and filtering with .filter()

You can use groupby with the .filter() method to remove whole groups of rows from a DataFrame based on a boolean condition.

In this exercise, you'll take the February sales data and remove entries from companies that purchased less than or equal to 35 Units in the whole month.

First, you'll identify how many units each company bought for verification. Next you'll use the .filter() method after grouping by 'Company' to remove all rows belonging to companies whose sum over the 'Units' column was less than or equal to 35. Finally, verify that the three companies whose total Units purchased were less than or equal to 35 have been filtered out from the DataFrame.

Instructions
100 XP
  • Group sales by 'Company'. Save the result as by_company.
  • Compute and print the sum of the 'Units' column of by_company.
  • Call .filter() on by_company with lambda g:g['Units'].sum() > 35 as input and print the result.