Complete the code to filter groups with mean value greater than 50.
filtered = df.groupby('category').filter(lambda x: x['value'].[1]() > 50)
The mean() function calculates the average value for each group. We want groups where this average is greater than 50.
Complete the code to keep groups with more than 3 rows.
filtered = df.groupby('category').filter(lambda x: len(x) [1] 3)
<= will keep groups with 3 or fewer rows.== keeps only groups with exactly 3 rows.The len(x) gives the number of rows in each group. We want groups with more than 3 rows, so use >.
Fix the error in the code to filter groups where the max value is less than 100.
filtered = df.groupby('category').filter(lambda x: x['value'].[1]() [2] 100)
min() instead of max().>.We want the maximum value in each group to be less than 100. So use max() and the operator <.
Fill both blanks to filter groups where the sum of 'score' is at least 200.
filtered = df.groupby('team').filter(lambda x: x['score'].[1]() [2] 200)
mean() instead of sum().> instead of >=.We want the total sum of 'score' in each group to be at least 200, so use sum() and the operator >=.
Fill all three blanks to filter groups where the average 'age' is less than 30 and group size is more than 5.
filtered = df.groupby('department').filter(lambda x: x['age'].[1]() [2] 30 and len(x) [3] 5)
sum() instead of mean() for average.We check if the average age is less than 30 using mean() and <, and if the group size is more than 5 using len(x) > 5.