Use the right denominator for a rate and filter after grouping.
Step 1 of 3 · Learn
Turn a Boolean flag into a rate
For a complete True/False column, .mean() is the fraction of rows that are True: True counts as 1 and False as 0. The result is a proportion from 0 to 1, not a percentage. In this dataset, every search has a recorded result_count.
index
group
results
0
A
0
1
A
4
2
B
2
↓
index
group
zero_rate
0
A
0.5
1
B
0
One of two A rows has zero results, so its rate is 0.5.
Keep the numerator and denominator
Sum the zero-result flag for the numerator and count all searches for the denominator. Divide those counts within each group. Filtering to zero-result searches before counting would remove the denominator's other searches.
Filter the report, not the source rows
First aggregate all search rows. Then filter the report by its search count. An inclusive minimum uses >=; exactly the minimum qualifies. Keep missing device keys with dropna=False.
index
group
zero
rows
0
A
1
2
1
B
0
1
↓
index
group
zero
rows
rate
0
A
1
2
0.5
The small group is removed after its counts and rate are calculated.
▷ Your turn
Return device and zero_result_rate for each device. The rate is the fraction of all searches with result_count equal to 0. Include missing devices if present; sort device ascending, missing last. Do not round or multiply by 100. Save the DataFrame as result.