Skip to content

Aggregations

Aggregations reduce a column to a single value — min, max, sum, mean, std. Like operators, they return an Object; call .data() to get the number. The reduction runs in ClickHouse, so it works the same on ten rows or ten billion.

Basic statistics

data = [10.0, 20.0, 30.0, 40.0, 50.0]
obj = await create_object_from_value(data)
print(f"Created object: {obj}")
print(f"Data: {data}\n")

min_val = await obj.min().data()
max_val = await obj.max().data()
sum_val = await obj.sum().data()
mean_val = await obj.mean().data()
std_val = await obj.std().data()

print(f"Minimum:          {min_val}")  # → 10.0
print(f"Maximum:          {max_val}")  # → 50.0
print(f"Sum:              {sum_val}")  # → 150.0
print(f"Mean:             {mean_val}")  # → 30.0
print(f"Std Deviation:    {std_val}")  # → 14.142135623730951

A worked example

The same methods describe any numeric column — here, a day of temperature readings:

temperatures = [72.5, 75.0, 68.3, 71.2, 74.8, 69.5, 73.1, 76.2]
obj_temp = await create_object_from_value(temperatures)

print(f"Daily temperatures (°F): {temperatures}\n")

min_temp = await obj_temp.min().data()
max_temp = await obj_temp.max().data()
avg_temp = await obj_temp.mean().data()
std_temp = await obj_temp.std().data()

print("Temperature Analysis:")
print(f"  Minimum:          {min_temp:.1f}°F")  # → 68.3°F
print(f"  Maximum:          {max_temp:.1f}°F")  # → 76.2°F
print(f"  Average:          {avg_temp:.1f}°F")  # → 72.6°F
print(f"  Std Deviation:    {std_temp:.2f}°F")  # → 2.60°F
print(f"  Temperature Range: {max_temp - min_temp:.1f}°F")

Next

Multi-Column Data → — group rows and aggregate per group.

See Also