Repeat a device statistic beside each search and rank timings within device groups.
Step 1 of 3 · Learn
Keep rows while adding a summary
.groupby(...).transform("mean") returns one value per input row, aligned to its original index. It repeats each group mean beside that group’s rows instead of reducing the table to one row per group. Use dropna=False to keep a missing-device group.
index
group
value
0
A
10
1
B
50
2
A
30
↓
index
group
value
group_mean
0
A
10
20
1
B
50
50
2
A
30
20
Three input rows remain three rows; group A's mean appears twice.
Compare with the group average
Subtract the group mean from the original response time. A positive difference means slower than that device's average; a negative difference means faster. Means ignore missing timings. A row with a missing timing has a missing difference.
State the ranking rule
Group .rank(method="dense", ascending=False) puts the largest timing at rank 1 within each device. Equal timings share a rank and the next distinct timing gets the next integer. Missing timings keep a missing rank; the default rank method is average, not dense.
index
group
value
0
A
30
1
A
30
2
A
10
3
B
20
↓
index
group
value
rank
0
A
30
1
1
A
30
1
2
A
10
2
3
B
20
1
Ties share rank 1; the next distinct value is rank 2, with a fresh ranking for B.
▷ Your turn
Return search_id, device, response_ms, and device_mean_ms for every search in source row order. Repeat each device's mean recorded response_ms on its rows, including missing device keys as a group. Ignore missing timings when calculating means and do not round. Save the DataFrame as result.