compareSegments = Array.from(d3.rollup(
data.filter(d => d.period_number > 0 && d.period_number <= segmentPlotPeriodsToShow),
values => ({
period_number: values[0].period_number,
segment: values[0].segment,
mean: d3.mean(values, d => d.percentage),
median: d3.median(values, d => d.percentage)
}),
d => `${d.period_number}/${d.segment}`
).values())