0
0
Pandasdata~10 mins

filter() for group-level filtering in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to filter groups with mean value greater than 50.

Pandas
filtered = df.groupby('category').filter(lambda x: x['value'].[1]() > 50)
Drag options to blanks, or click blank then click option'
Amean
Bmax
Csum
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of mean() will filter by total, not average.
Using max() or min() will filter by extreme values, not average.
2fill in blank
medium

Complete the code to keep groups with more than 3 rows.

Pandas
filtered = df.groupby('category').filter(lambda x: len(x) [1] 3)
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= will keep groups with 3 or fewer rows.
Using == keeps only groups with exactly 3 rows.
3fill in blank
hard

Fix the error in the code to filter groups where the max value is less than 100.

Pandas
filtered = df.groupby('category').filter(lambda x: x['value'].[1]() [2] 100)
Drag options to blanks, or click blank then click option'
Amin
Bmax
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using min() instead of max().
Using the wrong comparison operator like >.
4fill in blank
hard

Fill both blanks to filter groups where the sum of 'score' is at least 200.

Pandas
filtered = df.groupby('team').filter(lambda x: x['score'].[1]() [2] 200)
Drag options to blanks, or click blank then click option'
Asum
B>
C>=
Dmean
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() instead of sum().
Using > instead of >=.
5fill in blank
hard

Fill all three blanks to filter groups where the average 'age' is less than 30 and group size is more than 5.

Pandas
filtered = df.groupby('department').filter(lambda x: x['age'].[1]() [2] 30 and len(x) [3] 5)
Drag options to blanks, or click blank then click option'
Amean
B<
C>
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of mean() for average.
Mixing up comparison operators.