0
0
Data Analysis Pythondata~10 mins

filter() for group-level filtering in Data Analysis Python - 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 where the mean score is greater than 80.

Data Analysis Python
filtered = df.groupby('team').filter(lambda x: x['score'].[1]() > 80)
Drag options to blanks, or click blank then click option'
Amax
Bmin
Cmean
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() instead of mean()
Using max() or min() which do not calculate average
2fill in blank
medium

Complete the code to filter groups where the number of rows is at least 3.

Data Analysis Python
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 < instead of >=
Using == which only keeps groups with exactly 3 rows
3fill in blank
hard

Fix the error in the code to filter groups where the maximum value in 'value' column is less than 50.

Data Analysis Python
filtered = df.groupby('group').filter(lambda x: x['value'].[1]() < 50)
Drag options to blanks, or click blank then click option'
Asum
Bmax
Cmean
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using min() which returns the smallest value
Using mean() or sum() which do not give the maximum
4fill in blank
hard

Fill both blanks to filter groups where the sum of 'points' is greater than 100 and the group size is at least 5.

Data Analysis Python
filtered = df.groupby('team').filter(lambda x: x['points'].[1]() [2] 100 and len(x) >= 5)
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 create a dictionary of group names and their average 'score' for groups with average score above 70.

Data Analysis Python
result = {group: data['score'].[1]() for group, data in df.groupby('[2]') if data['score'].[3]() > 70}
Drag options to blanks, or click blank then click option'
Amean
Bteam
Dcategory
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'category' instead of 'team' for grouping
Using sum() instead of mean() for averages