Skip to content
Advertisement

How to drop entire group in pandas if any other columns meet certain criteria?

I have a df that looks like this:

JavaScript

Currently, I am using this line of code to filter on the df so that only rows that are of a period PRE and have an amount of more than 10 are included:

JavaScript

What I realized though is that I actually need to remove the entire grouping from the df if even just the PRE period doesn’t satisfy the > 10 condition. So in that case I would need all 456 rows and 789 rows removed just because their PRE period row was below 10. How might I adjust my code to accomplish this?

Expected Output:

JavaScript

Advertisement

Answer

Please try:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement