Combine group averages with their real denominators
See why groups of different sizes give a combined mean of 18 rather than 15, with a short Python example.
On this page
The short answer
To combine arithmetic means of compatible observations, weight each group mean by the number of observations actually used in that mean. A group of two with mean 10 and a group of eight with mean 20 give (2*10 + 8*20)/10 = 18. Their unweighted mean of means is 15 and answers a different question. Keep the denominators with every reported mean, especially when missing values are excluded.
Identify the quantity being averaged
Before combining summaries, confirm that they describe the same quantity in the same units and under compatible inclusion rules. A response time measured in seconds cannot be combined directly with one reported in milliseconds without conversion. Also distinguish an average per observation from an average per group. Both can be meaningful, but they give different importance to a small group and a large group.
Retain the denominator used by each mean
For an arithmetic mean, multiplying the mean by its observation count reconstructs the group total, subject to rounding. Summing those totals and dividing by the summed counts gives the combined mean for disjoint compatible groups. The count must refer to observations that contributed to the mean. A nominal department size is the wrong denominator if only some members supplied the measured value.
Calculate the unequal-group example
Construct group A with count 2 and mean 10, so its total is 20. Group B has count 8 and mean 20, giving total 160. The combined total is 180 over 10 observations, hence mean 18. Averaging 10 and 20 directly gives 15 because it assigns equal weight to the two groups. These hypothetical summaries show the distinction without claiming an observed dataset or benchmark.
Use a short Python calculation
Python 3.11 and later support weights in statistics.fmean. The example supplies means and their matching counts, producing an expected value of 18.0. The code does not retrieve a dataset or validate whether the counts were collected correctly. Treat this as a calculation of supplied inputs. If you need exact decimal accounting, consider the numeric representation separately rather than assuming floating-point output is exact for all values.
from statistics import fmean
group_means = [10, 20]
observed_counts = [2, 8]
combined_mean = fmean(group_means, weights=observed_counts)
print(combined_mean)
Combine percentages through compatible counts
Suppose one group has 1 success in 2 trials and another has 4 in 8. The combined success proportion is 5/10, or 50 percent. In general, retain success counts and trial counts instead of averaging displayed percentages without their denominators. Different definitions of a trial or overlapping groups invalidate a simple pooled interpretation. Counts also avoid some information loss caused by percentages rounded for presentation.
Handle missing observations consistently
A mean computed after excluding missing values must be paired with the number of nonmissing observations for that same variable and inclusion rule. Different columns can have different valid counts even within one group. pandas mean can skip missing values, so a raw row count is not automatically the appropriate weight. If missingness is systematic, correct arithmetic does not remove the resulting representativeness problem.
Diagnose accidental equal weighting
When a combined number looks surprising, write down each mean, count and reconstructed total before changing the formula. Check whether the intended question gives equal importance to groups or to individual observations. Equal weighting of group means is appropriate for an explicitly group-level question, and can coincide with pooling when group counts are equal. It should not be silently presented as the overall observation-level mean when counts differ.
Recognize limits of summary pooling
An arithmetic weighted mean of medians does not recover a pooled median. Rates such as speed may require a different formula depending on which exposure is held constant. Overlapping groups can count the same observation more than once. Rounded means introduce reconstruction error, and a zero total weight leaves no defined pooled mean. Preserve raw totals and counts when feasible, and state what information the summaries do not contain.
Things to check
- Check units and inclusion rules.
- Keep the actual nonmissing count with each mean.
- Distinguish observation-level and group-level questions.
- Prefer raw numerator and denominator counts for percentages.
- Do not pool medians with the mean formula.
Where this applies
Pooling assumes compatible arithmetic means with corresponding counts and no unintended double counting. It does not repair missing-data bias, recover a pooled median, or establish the correct formula for every rate. The Python weights example requires Python 3.11+.