Name several aggregations and summarize each country-device pair.
Step 1 of 3 · Learn
Name each metric
Named .agg() entries use output_name=("source_column", "operation"). Combine size, count, nunique, mean, or median in one report. Size counts all rows; count and nunique exclude missing values.
index
group
value
0
A
10
1
A
30
2
B
20
↓
index
group
rows
mean_value
0
A
2
20
1
B
1
20
Named aggregation produces readable metric columns in one pass.
Group by a pair of keys
Pass a list of columns to group by each distinct combination. dropna=False keeps combinations with missing keys. A country-device report has one row per pair, not one row per country.
index
region
device
value
0
A
phone
10
1
A
phone
30
2
A
web
50
3
B
web
20
↓
index
region
device
rows
median_value
0
A
phone
2
20
1
A
web
1
50
2
B
web
1
20
Two rows share a pair of keys; the other pairs remain separate.
Interpret distinct counts and medians
A median is the middle recorded value after sorting; with an even number of values, it averages the middle two. Distinct users are counted within each group. Do not add group-level distinct counts to get a global total: a user can appear in several groups.
▷ Your turn
Return device, searches, and mean_response_ms for each device. Include missing devices if present, sort device ascending with missing last, and do not round. Save the DataFrame as result.