October 2019
Beginner to intermediate
674 pages
16h 43m
English
The filter method enables us to apply filtering to a groupby object to result in a subset of the initial object.
Let's apply filter to the sample sales data to compute only the sums of those groups whose length is more than 10000, when grouped across Category:
filtered_df = sales_data[["Category", "Quantity"]].set_index("Category").groupby("Category").filter(lambda x: len(x) > 10000)filtered_df.groupby("Category").sum()
The following will be the output:

Now, as you can see, filtering removes the Furniture category, whose length is less than 10000.
Read now
Unlock full access